var EcosystemsActions, EcosystemsStore, FAILED, LOADING, _, flux;
_ = require('underscore');
flux = require('flux-react');
LOADING = 'loading';
FAILED = 'failed';
EcosystemsActions = flux.createActions(['load', 'loaded', 'FAILED']);
EcosystemsStore = flux.createStore({
actions: _.values(EcosystemsActions),
_asyncStatus: null,
load: function() {
this._asyncStatus = LOADING;
return this.emit('load');
},
loaded: function(ecosystems) {
this._ecosystems = ecosystems;
return this.emit('loaded');
},
FAILED: function() {
this._asyncStatus = FAILED;
return this.emit('failed');
},
exports: {
isLoaded: function() {
return !_.isEmpty(this._ecosystems);
},
isLoading: function() {
return this._asyncStatus === LOADING;
},
isFailed: function() {
return this._asyncStatus === FAILED;
},
allBooks: function() {
return _.map(this._ecosystems, function(ecosystem) {
return _.extend(_.first(ecosystem.books), {
ecosystemId: "" + ecosystem.id,
ecosystemComments: ecosystem.comments
});
});
},
first: function() {
return _.first(this._ecosystems);
},
getBook: function(ecosystemId) {
return _.first(_.findWhere(this._ecosystems, {
id: parseInt(ecosystemId, 10)
}).books);
}
}
});
module.exports = {
EcosystemsActions: EcosystemsActions,
EcosystemsStore: EcosystemsStore
};
|