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
};
|