2015-03-17 22:01:46 +01:00
|
|
|
var Reflux = require('reflux');
|
|
|
|
var StrategyActions = require('./StrategyActions');
|
|
|
|
var filter = require('lodash/collection/filter');
|
|
|
|
|
|
|
|
var _strategies = [];
|
|
|
|
|
|
|
|
// Creates a DataStore
|
|
|
|
var StrategyStore = Reflux.createStore({
|
|
|
|
|
|
|
|
// Initial setup
|
|
|
|
init: function() {
|
2015-03-17 22:52:10 +01:00
|
|
|
this.listenTo(StrategyActions.init.completed, this.setStrategies);
|
2015-03-17 22:01:46 +01:00
|
|
|
this.listenTo(StrategyActions.create.completed, this.onCreate);
|
|
|
|
this.listenTo(StrategyActions.remove.completed, this.onRemove);
|
|
|
|
},
|
|
|
|
|
|
|
|
onCreate: function(strategy) {
|
|
|
|
this.setStrategies(_strategies.concat([strategy]));
|
2014-12-09 09:22:54 +01:00
|
|
|
},
|
|
|
|
|
2015-03-17 22:01:46 +01:00
|
|
|
onRemove: function(strategy) {
|
|
|
|
var strategies = filter(_strategies, function(item) {
|
|
|
|
return item.name !== strategy.name;
|
2014-11-01 14:52:37 +01:00
|
|
|
});
|
2015-03-17 22:01:46 +01:00
|
|
|
this.setStrategies(strategies);
|
|
|
|
},
|
|
|
|
|
|
|
|
setStrategies: function(strategies) {
|
|
|
|
_strategies = strategies;
|
|
|
|
this.trigger(_strategies);
|
|
|
|
},
|
|
|
|
|
|
|
|
getStrategies: function() {
|
|
|
|
return _strategies;
|
|
|
|
},
|
|
|
|
|
|
|
|
initStore: function(strategies) {
|
|
|
|
_strategies = strategies;
|
2014-11-01 14:52:37 +01:00
|
|
|
}
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
2014-11-01 14:52:37 +01:00
|
|
|
|
|
|
|
module.exports = StrategyStore;
|