import Reflux from 'reflux'; import assign from 'object-assign'; import RESTMixin from './rest_mixin'; import BotActions from './bot_actions'; const urlRoot = 'bots'; let _bots = []; const _byId = {}; const BotStore = Reflux.createStore({ listenables: BotActions, mixins: [RESTMixin(urlRoot, BotActions)], onFetchCompleted(resp) { // Single model if (resp.id) { // Exists let existing; if (existing = _byId[resp.id]) { assign(existing, resp); // Add it } else { _byId[resp.id] = resp; _bots.push(resp); } // Whole collection } else { _bots = resp; } this.trigger(); }, onFetchfailed(err) { // do something }, onSaveCompleted(resp) { assign(_byId(resp.id), resp); @trigger(); }, onSaveFailed(err) { }, onDeleteCompleted(id) { }, onDeleteFailed(id, err) { } getBots() { return _bots; } }); export default BotStore;