1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/packages/unleash-frontend/public/js/stores/StrategyStore.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const Reflux = require('reflux');
const StrategyActions = require('./StrategyActions');
const filter = require('lodash/collection/filter');
2015-03-17 22:01:46 +01:00
2016-06-18 21:53:18 +02:00
let _strategies = [];
2015-03-17 22:01:46 +01:00
// Creates a DataStore
2016-06-18 21:53:18 +02:00
const StrategyStore = Reflux.createStore({
2015-03-17 22:01:46 +01:00
// Initial setup
2016-07-02 11:54:50 +02:00
init () {
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);
},
2016-07-02 11:54:50 +02:00
onCreate (strategy) {
2015-03-17 22:01:46 +01:00
this.setStrategies(_strategies.concat([strategy]));
2014-12-09 09:22:54 +01:00
},
2016-07-02 11:54:50 +02:00
onRemove (strategy) {
2016-06-18 21:53:18 +02:00
const strategies = filter(_strategies, item => item.name !== strategy.name);
2015-03-17 22:01:46 +01:00
this.setStrategies(strategies);
},
2016-07-02 11:54:50 +02:00
setStrategies (strategies) {
2015-03-17 22:01:46 +01:00
_strategies = strategies;
this.trigger(_strategies);
},
2016-07-02 11:54:50 +02:00
getStrategies () {
2015-03-17 22:01:46 +01:00
return _strategies;
},
2016-07-02 11:54:50 +02:00
initStore (strategies) {
2015-03-17 22:01:46 +01:00
_strategies = strategies;
2016-06-18 21:55:46 +02:00
},
2015-03-17 22:01:46 +01:00
});
module.exports = StrategyStore;