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

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-03-17 18:31:55 +01:00
var Reflux = require('reflux');
var FeatureActions = require('./FeatureToggleActions');
var Timer = require('../utils/Timer');
var Server = require('./FeatureToggleServerFacade');
var filter = require('lodash/collection/filter');
var sortBy = require('lodash/collection/sortBy');
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);
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));
},
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;
}
});
module.exports = FeatureStore;