2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
2016-06-18 21:55:46 +02:00
|
|
|
const Reflux = require('reflux');
|
2016-06-18 21:53:18 +02:00
|
|
|
const StrategyAPI = require('./StrategyAPI');
|
2015-03-17 22:01:46 +01:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const StrategyActions = Reflux.createActions({
|
|
|
|
init: { asyncResult: true },
|
|
|
|
create: { asyncResult: true },
|
|
|
|
remove: { asyncResult: true },
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
StrategyActions.init.listen(function () {
|
2016-06-18 21:53:18 +02:00
|
|
|
StrategyAPI.getStrategies((err, strategies) => {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (err) {
|
2015-03-17 22:52:10 +01:00
|
|
|
this.failed(err);
|
|
|
|
} else {
|
|
|
|
this.completed(strategies);
|
|
|
|
}
|
2016-06-18 21:53:18 +02:00
|
|
|
});
|
2015-03-17 22:52:10 +01:00
|
|
|
});
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
StrategyActions.create.listen(function (feature) {
|
2016-06-18 21:53:18 +02:00
|
|
|
StrategyAPI.createStrategy(feature, err => {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (err) {
|
2015-03-17 22:01:46 +01:00
|
|
|
this.failed(err);
|
|
|
|
} else {
|
|
|
|
this.completed(feature);
|
|
|
|
}
|
2016-06-18 21:53:18 +02:00
|
|
|
});
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
StrategyActions.remove.listen(function (feature) {
|
2016-06-18 21:53:18 +02:00
|
|
|
StrategyAPI.removeStrategy(feature, err => {
|
2016-04-24 22:41:37 +02:00
|
|
|
if (err) {
|
2015-03-17 22:01:46 +01:00
|
|
|
this.failed(err);
|
|
|
|
} else {
|
|
|
|
this.completed(feature);
|
|
|
|
}
|
2016-06-18 21:53:18 +02:00
|
|
|
});
|
2015-03-17 22:01:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = StrategyActions;
|