Code coverage report for src/flux/ecosystems.coffee

Statements: 38.1% (8 / 21)      Branches: 100% (0 / 0)      Functions: 0% (0 / 10)      Lines: 38.1% (8 / 21)      Ignored: none     

All files » src/flux/ » ecosystems.coffee
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                                                            
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
};