bfitch / cerebral-falcor-module

Cerebral integration for Netfilx's Falcor
6 stars 2 forks source link

cerebral-falcor-module [experimental]

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

Install

npm install cerebral-falcor-module

Usage

// main.js
import FalcorModule from 'cerebral-falcor-module';

controller.register({
  falcor: FalcorModule({
    model: model // source defaults to: '/model.json',
  })
});
const getTodosLength = ({output, services}) => {
  services.falcor.get(['todosLength']).
    then(response => output(response.json)).
    catch(response => output.error);
}

API (Incomplete)

TODO

Thanks