1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00

Moved server-stuff to the actions

This commit is contained in:
Ivar Conradi Østhus 2015-03-16 21:27:56 +01:00
parent d495bb1829
commit 860a998623
2 changed files with 58 additions and 54 deletions

View File

@ -1,7 +1,51 @@
var Reflux = require("reflux"); var Reflux = require("reflux");
module.exports = { var Server = require('./FeatureToggleServerFacade');
create: Reflux.createAction({ asyncResult: true }),
update: Reflux.createAction({ asyncResult: true }), var FeatureToggleActions = Reflux.createActions({
archive: Reflux.createAction({ asyncResult: true }), 'create': { asyncResult: true },
revive: Reflux.createAction({ asyncResult: true }) 'update': { asyncResult: true },
}; 'archive': { asyncResult: true },
'revive': { asyncResult: true }
});
FeatureToggleActions.create.listen(function(feature){
Server.createFeature(feature, function(error) {
if(error) {
this.failed(error);
} else {
this.completed(feature);
}
}.bind(this));
});
FeatureToggleActions.update.listen(function(feature){
Server.updateFeature(feature, function(error) {
if(error) {
this.failed(error);
} else {
this.completed(feature);
}
}.bind(this));
});
FeatureToggleActions.archive.listen(function(feature){
Server.archiveFeature(feature, function(error) {
if(error) {
this.failed(error);
} else {
this.completed(feature);
}
}.bind(this));
});
FeatureToggleActions.revive.listen(function(feature){
Server.reviveFeature(feature, function(error) {
if(error) {
this.failed(error);
} else {
this.completed(feature);
}
}.bind(this));
});
module.exports = FeatureToggleActions;

View File

@ -10,10 +10,10 @@ var _archivedToggles = [];
var FeatureStore = Reflux.createStore({ var FeatureStore = Reflux.createStore({
// Initial setup // Initial setup
init: function() { init: function() {
this.listenTo(FeatureActions.create, this.onCreate); this.listenTo(FeatureActions.create.completed, this.onCreate);
this.listenTo(FeatureActions.update, this.onUpdate); this.listenTo(FeatureActions.update.completed, this.onUpdate);
this.listenTo(FeatureActions.archive, this.onArchive); this.listenTo(FeatureActions.archive.completed, this.onArchive);
this.listenTo(FeatureActions.revive, this.onRevive); this.listenTo(FeatureActions.revive.completed, this.onRevive);
this.timer = new Timer(this.loadDataFromServer, 30*1000); this.timer = new Timer(this.loadDataFromServer, 30*1000);
this.timer.start(); this.timer.start();
@ -31,47 +31,7 @@ var FeatureStore = Reflux.createStore({
}, },
onCreate: function(feature) { onCreate: function(feature) {
Server.createFeature(feature, function(error) {
if(error) {
FeatureActions.create.failed(error);
} else {
this.setToggles([feature].concat(_featureToggles)); this.setToggles([feature].concat(_featureToggles));
FeatureActions.create.completed();
}
}.bind(this));
},
onArchive: function(feature) {
Server.archiveFeature(feature, function(error) {
if(error) {
FeatureActions.archive.failed(error);
} else {
this.archiveToggle(feature);
FeatureActions.archive.completed();
}
}.bind(this));
},
onUpdate: function(feature) {
Server.updateFeature(feature, function(error) {
if(error) {
FeatureActions.update.failed(error);
} else {
this.updateToggle(feature);
FeatureActions.update.completed();
}
}.bind(this));
},
onRevive: function(feature) {
Server.reviveFeature(feature, function(error) {
if(error) {
FeatureActions.revive.failed(error);
} else {
this.revive(feature);
FeatureActions.revive.completed();
}
}.bind(this));
}, },
setToggles: function(toggles) { setToggles: function(toggles) {
@ -79,7 +39,7 @@ var FeatureStore = Reflux.createStore({
this.trigger(); this.trigger();
}, },
updateToggle: function(feature) { onUpdate: function(feature) {
var idx; var idx;
_featureToggles.forEach(function(item, i) { _featureToggles.forEach(function(item, i) {
if(item.name === feature.name) { if(item.name === feature.name) {
@ -90,7 +50,7 @@ var FeatureStore = Reflux.createStore({
this.trigger(); this.trigger();
}, },
archiveToggle: function(feature) { onArchive: function(feature) {
var idx; var idx;
_featureToggles.forEach(function(item, i) { _featureToggles.forEach(function(item, i) {
if(item.name === feature.name) { if(item.name === feature.name) {
@ -102,7 +62,7 @@ var FeatureStore = Reflux.createStore({
this.trigger(); this.trigger();
}, },
revive: function(item) { onRevive: function(item) {
var newStore = _archivedToggles.filter(function(f) { var newStore = _archivedToggles.filter(function(f) {
return f.name !== item.name; return f.name !== item.name;
}); });