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
2020-02-20 08:30:27 +01:00

42 lines
1.0 KiB
JavaScript

'use strict';
const Reflux = require('reflux');
const StrategyActions = require('./StrategyActions');
const filter = require('lodash/collection/filter');
let _strategies = [];
// Creates a DataStore
const StrategyStore = Reflux.createStore({
// Initial setup
init () {
this.listenTo(StrategyActions.init.completed, this.setStrategies);
this.listenTo(StrategyActions.create.completed, this.onCreate);
this.listenTo(StrategyActions.remove.completed, this.onRemove);
},
onCreate (strategy) {
this.setStrategies(_strategies.concat([strategy]));
},
onRemove (strategy) {
const strategies = filter(_strategies, item => item.name !== strategy.name);
this.setStrategies(strategies);
},
setStrategies (strategies) {
_strategies = strategies;
this.trigger(_strategies);
},
getStrategies () {
return _strategies;
},
initStore (strategies) {
_strategies = strategies;
},
});
module.exports = StrategyStore;