Code coverage report for src/flux/transition.coffee

Statements: 91.67% (22 / 24)      Branches: 75% (6 / 8)      Functions: 80% (4 / 5)      Lines: 91.67% (22 / 24)      Ignored: none     

All files » src/flux/ » transition.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                 54× 54× 54× 54×   54× 31×                                                
var DestinationHelper, TransitionActions, TransitionStore, _, flux;
 
_ = require('underscore');
 
flux = require('flux-react');
 
DestinationHelper = require('../helpers/routes-and-destinations');
 
TransitionActions = flux.createActions(['load', 'reset', '_get']);
 
TransitionStore = flux.createStore({
  actions: _.values(TransitionActions),
  _local: [],
  load: function(change, router) {
    var path, type;
    type = change.type, path = change.path;
    Eif (type == null) {
      type = 'push';
    }
    if (type === 'push' && DestinationHelper.shouldRememberRoute(change, router)) {
      return this._local.push(path);
    }
  },
  reset: function() {
    return this._local = [];
  },
  _get: function() {
    return this._local;
  },
  exports: {
    getPrevious: function(router) {
      var currentPath, history, matchRoutes, pathIndex;
      matchRoutes = router.match;
      currentPath = DestinationHelper.destinationFromPath(router.getCurrentPath(), matchRoutes);
      history = this._get();
      pathIndex = _.findLastIndex(history, function(path) {
        return currentPath !== DestinationHelper.destinationFromPath(path, matchRoutes);
      });
      Iif (-1 === pathIndex) {
        return {};
      }
      return {
        path: history[pathIndex],
        name: DestinationHelper.destinationFromPath(history[pathIndex], matchRoutes)
      };
    }
  }
});
 
module.exports = {
  TransitionActions: TransitionActions,
  TransitionStore: TransitionStore
};