1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Added init-error events

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

View File

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

View File

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