Transparently syncs your cerebral model with falcor's cache, intelligently caching client data.
Whenver a change is fired by falcor, cererbral-falcor
diffs falcor's cache with your cererbral model's current state. It calculates the difference, patching the changed data to cerebral. This happens in the background, allowing your components to synchronosly bind to cerebral and update the UI.
Note: falcor --> cerebral
data synchronization is unidirectional, meaning updates to the falcor cache are pushed to cerebral, but not vice-versa. All changes to falcor data are through the exposed falcor API (get, set, call).
Falcor's data is namespaced in your model to prevent overwriting cerebral only data. The defalut namespace for retreiving falcor data is falcor: { falcor: {} }
.
Basic Todo Demo: https://github.com/bfitch/cerebral-falcor-todos
npm install cerebral-falcor-module
- Register the module in cerebral:
// main.js
import FalcorModule from 'cerebral-falcor-module';
controller.register({
falcor: FalcorModule({
model: model // source defaults to: '/model.json',
})
});
- Define the namespace in baobab:
const model = Model({
falcor: {} // can also define a custom name
});
- falcor will now be available to your actions as a
service
:
const getTodosLength = ({output, services}) => {
services.falcor.get(['todosLength']).
then(response => output(response.json)).
catch(response => output.error);
}
- get state from cerebral:
({state}) => {
state.get(['falcor', 'todos']);
}
get(path)
call(functionPath, args, refPaths, thisPaths)
- expose
set
- accept falcor initialization options
{}
- perf audit
- tests
- @ekosz for his
falcor-expand-cache
package, which makes the diff and patch strategy possible. Also forredux-falcor
for the general approach.