1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/public/js/stores/ArchivedToggleStore.js
Anders Olsen Sandvik a96a9f38ce #108 Add eslint-config-spt and remove jshint (#111)
* #108 Add eslint-config-spt

* #108 Ignore bundle.js file

* #108 Change eslint ignore path to a glob file

* Remove jshint and follow more of eslint rules
2020-02-20 08:30:24 +01:00

48 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;