These are chat archives for ractivejs/ractive

8th
Jun 2017
Joseph
@fskreuz
Jun 08 2017 12:23
Is this a close approximation of what Ractive does with expressions?
// Expression parsing
Ractive.parse('{{ a + b }}{{ c + d }}');

// {
//   "v": 4,
//   "t": [
//     {
//       "t": 2,
//       "x": {
//         "r": ["a","b"], <-- dependencies here
//         "s": "_0+_1"    <-- expression string here
//       }
//     },
//     {
//       "t": 2,
//       "x": {
//         "r": ["c","d"], <-- dependencies here
//         "s": "_0+_1"    <-- expression string here
//       }
//     }
//   ],
//   "e": {}
// }

// Building and caching of the expression resolver of `_0+_1`
const expressionFunctionsCache = {};
expressionFunctionsCache['_0+_1'] = new Function('_0', '_1', 'return _0+_1');

// Evaluate {{ a + b }}
const dep = ['a', 'b'];
const exp = '_0+_1'
const arg = dep.map(instance.get);
const val = expressionFunctionsCache[exp].apply(instance, arg);

// Evaluate {{ c + d }}
const dep = ['c', 'd'];
const exp = '_0+_1'
const arg = dep.map(instance.get);
const val = expressionFunctionsCache[exp].apply(instance, arg);
Trying to create a visual example that one can follow through :D
Martin Kolárik
@MartinKolarik
Jun 08 2017 12:34
yep that looks good
Joseph
@fskreuz
Jun 08 2017 12:37
:tada:
Juan C. Andreu
@andreujuanc
Jun 08 2017 14:17
Everytime I check Ractive's source code I feel amazed.
Joseph
@fskreuz
Jun 08 2017 14:25
The complexity is only because there's a lot of modules. When visualized in isolation, it's amazing.
Joseph
@fskreuz
Jun 08 2017 14:56
For anyone that's lurking in chat but not on github, here's a PR for review ractivejs/ractive#3000
Also a good opportunity to look at how Ractive actually makes expressions in mustaches work