2015-03-17 18:31:55 +01:00
|
|
|
var Reflux = require('reflux');
|
|
|
|
var FeatureActions = require('./FeatureToggleActions');
|
|
|
|
var filter = require('lodash/collection/filter');
|
|
|
|
var sortBy = require('lodash/collection/sortBy');
|
|
|
|
|
|
|
|
var _archivedToggles = [];
|
|
|
|
|
|
|
|
// Creates a DataStore
|
|
|
|
var FeatureStore = Reflux.createStore({
|
2015-03-17 20:34:19 +01:00
|
|
|
|
|
|
|
// Initial setup
|
|
|
|
init: function() {
|
2015-03-17 22:52:10 +01:00
|
|
|
this.listenTo(FeatureActions.initArchive.completed, this.onInit);
|
2015-03-17 20:34:19 +01:00
|
|
|
this.listenTo(FeatureActions.archive.completed, this.onArchive);
|
|
|
|
this.listenTo(FeatureActions.revive.completed, this.onRevive);
|
|
|
|
},
|
|
|
|
|
2015-03-17 22:52:10 +01:00
|
|
|
onInit: function(toggles) {
|
|
|
|
_archivedToggles = toggles;
|
|
|
|
this.trigger();
|
2015-03-17 20:34:19 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
onArchive: function(feature) {
|
|
|
|
var toggles = _archivedToggles.concat([feature]);
|
|
|
|
_archivedToggles = sortBy(toggles, 'name');
|
|
|
|
this.trigger();
|
|
|
|
},
|
|
|
|
|
|
|
|
onRevive: function(item) {
|
|
|
|
var newStore = filter(_archivedToggles, function(f) {
|
|
|
|
return f.name !== item.name;
|
|
|
|
});
|
|
|
|
|
|
|
|
_archivedToggles = sortBy(newStore, 'name');
|
|
|
|
this.trigger();
|
|
|
|
},
|
|
|
|
|
|
|
|
getArchivedToggles: function() {
|
|
|
|
return _archivedToggles;
|
|
|
|
},
|
|
|
|
|
|
|
|
initStore: function(archivedToggles) {
|
|
|
|
_archivedToggles = archivedToggles;
|
|
|
|
}
|
2015-03-17 18:31:55 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = FeatureStore;
|