-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
33 lines (29 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import falcor from 'falcor';
import HttpDataSource from 'falcor-http-datasource';
import _expandCache from 'falcor-expand-cache';
import _diff from 'deep-diff';
export default function(options, expandCache=_expandCache, diff=_diff) {
const model = options.model;
const namespace = options.namespace || 'falcor';
const source = options.source || '/model.json';
const falcorModel = new falcor.Model({
source: new HttpDataSource(source)
});
falcorModel._root.onChange = function() {
const falcorCache = expandCache(falcorModel.getCache());
const falcorChanges = diff(model.tree.get([namespace]), falcorCache);
falcorChanges.forEach(change => model.tree.set([namespace].concat(change.path), change.rhs));
}
return {
init({name, controller}) {
},
services: {
get(query) {
return falcorModel.get(query)
},
call(functionPath, args, refPaths, thisPaths=[]) {
return falcorModel.call(functionPath, args, refPaths, thisPaths)
}
}
}
}