1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00

Added init-error events

This commit is contained in:
Ivar Conradi Østhus 2015-03-17 20:34:19 +01:00
parent 8ba685b67a
commit 945f4761d5
2 changed files with 43 additions and 34 deletions

View File

@ -1,5 +1,6 @@
var Reflux = require('reflux'); var Reflux = require('reflux');
var FeatureActions = require('./FeatureToggleActions'); var FeatureActions = require('./FeatureToggleActions');
var ErrorActions = require('./ErrorActions');
var Timer = require('../utils/Timer'); var Timer = require('../utils/Timer');
var Server = require('./FeatureToggleServerFacade'); var Server = require('./FeatureToggleServerFacade');
var filter = require('lodash/collection/filter'); var filter = require('lodash/collection/filter');
@ -9,47 +10,53 @@ var _archivedToggles = [];
// Creates a DataStore // Creates a DataStore
var FeatureStore = Reflux.createStore({ var FeatureStore = Reflux.createStore({
//The store should be split in two: toggleStore && archivedToggleStore!
// Initial setup // Initial setup
init: function() { init: function() {
this.listenTo(FeatureActions.archive.completed, this.onArchive); this.listenTo(FeatureActions.archive.completed, this.onArchive);
this.listenTo(FeatureActions.revive.completed, 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();
}, },
loadDataFromServer: function() { loadDataFromServer: function() {
//TODO: this should not be part of the store! //TODO: this should not be part of the store!
Server.getArchivedFeatures(function(err, archivedToggles) { Server.getArchivedFeatures(function(err, archivedToggles) {
_archivedToggles = archivedToggles;
this.trigger();
}.bind(this));
},
onArchive: function(feature) { if(err) {
var toggles = _archivedToggles.concat([feature]); ErrorActions.error(err);
_archivedToggles = sortBy(toggles, 'name'); return;
this.trigger(); } else {
}, _archivedToggles = archivedToggles;
this.trigger(_archivedToggles);
}
onRevive: function(item) { }.bind(this));
var newStore = filter(_archivedToggles, function(f) { },
return f.name !== item.name;
});
_archivedToggles = sortBy(newStore, 'name'); onArchive: function(feature) {
this.trigger(); var toggles = _archivedToggles.concat([feature]);
}, _archivedToggles = sortBy(toggles, 'name');
this.trigger();
},
getArchivedToggles: function() { onRevive: function(item) {
return _archivedToggles; var newStore = filter(_archivedToggles, function(f) {
}, return f.name !== item.name;
});
initStore: function(archivedToggles) { _archivedToggles = sortBy(newStore, 'name');
_archivedToggles = archivedToggles; this.trigger();
} },
getArchivedToggles: function() {
return _archivedToggles;
},
initStore: function(archivedToggles) {
_archivedToggles = archivedToggles;
}
}); });
module.exports = FeatureStore; module.exports = FeatureStore;

View File

@ -1,5 +1,6 @@
var Reflux = require('reflux'); var Reflux = require('reflux');
var FeatureActions = require('./FeatureToggleActions'); var FeatureActions = require('./FeatureToggleActions');
var ErrorActions = require('./ErrorActions');
var Server = require('./FeatureToggleServerFacade'); var Server = require('./FeatureToggleServerFacade');
var Timer = require('../utils/Timer'); var Timer = require('../utils/Timer');
var filter = require('lodash/collection/filter'); var filter = require('lodash/collection/filter');
@ -20,7 +21,7 @@ var FeatureStore = Reflux.createStore({
this.listenTo(FeatureActions.revive.completed, this.onRevive); this.listenTo(FeatureActions.revive.completed, this.onRevive);
//TODO: this should not be part of the store! //TODO: this should not be part of the store!
this.timer = new Timer(this.loadDataFromServer, 3*1000); this.timer = new Timer(this.loadDataFromServer, 30*1000);
this.timer.start(); this.timer.start();
}, },
@ -28,6 +29,7 @@ var FeatureStore = Reflux.createStore({
//TODO: this should not be part of the store! //TODO: this should not be part of the store!
Server.getFeatures(function(err, featureToggles) { Server.getFeatures(function(err, featureToggles) {
if(err) { if(err) {
ErrorActions.error(err);
return; return;
} else { } else {
this.setToggles(featureToggles); this.setToggles(featureToggles);