1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/public/js/stores/ArchivedToggleStore.js
2020-02-20 08:30:22 +01:00

49 lines
1.3 KiB
JavaScript

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({
// Initial setup
init: function() {
this.listenTo(FeatureActions.initArchive.completed, this.onInit);
this.listenTo(FeatureActions.archive.completed, this.onArchive);
this.listenTo(FeatureActions.revive.completed, this.onRevive);
},
onInit: function(toggles) {
_archivedToggles = toggles;
this.trigger();
},
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;