0.0.5 • Published 9 years ago

reflux-store-cache-mixin v0.0.5

Weekly downloads
10
License
MIT
Repository
github
Last release
9 years ago

reflux-store-cache-mixin

Reflux mixin for caching data.

Main usage is to reduce network calls for slowly changing data

Example

// Actions
import Reflux from 'reflux';

const testActions = Reflux.createActions({
  fetch: {
    children : [ 'completed', 'failed' ],
  },
});

export default testActions;

// Store
import Reflux from 'reflux';
import StoreCacheMixin from 'reflux-store-cache-mixin';
import { Map } from 'immutable';

export default Reflux.createStore({
  listenables : testActions,

  data : new Map(),

  mixins : [ StoreCacheMixin ],

  onFetch() {
      this.loadData('data', '*', (data, saveNewData) => {

        if (! data) {
          return fetchData()
            .tap(saveNewData)
            .then((nextData) => {
              this.data = nextData;
              return this.trigger(this.data);
            });
        }

        return this.trigger(this.data);

      });
  },
});
0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago