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

47 lines
1.2 KiB
JavaScript

'use strict';
const Reflux = require('reflux');
const FeatureActions = require('./FeatureToggleActions');
const filter = require('lodash/collection/filter');
const sortBy = require('lodash/collection/sortBy');
let _archivedToggles = [];
// Creates a DataStore
const FeatureStore = Reflux.createStore({
// Initial setup
init () {
this.listenTo(FeatureActions.initArchive.completed, this.onInit);
this.listenTo(FeatureActions.archive.completed, this.onArchive);
this.listenTo(FeatureActions.revive.completed, this.onRevive);
},
onInit (toggles) {
_archivedToggles = toggles;
this.trigger();
},
onArchive (feature) {
const toggles = _archivedToggles.concat([feature]);
_archivedToggles = sortBy(toggles, 'name');
this.trigger();
},
onRevive (item) {
const newStore = filter(_archivedToggles, f => f.name !== item.name);
_archivedToggles = sortBy(newStore, 'name');
this.trigger();
},
getArchivedToggles () {
return _archivedToggles;
},
initStore (archivedToggles) {
_archivedToggles = archivedToggles;
},
});
module.exports = FeatureStore;