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

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const Reflux = require('reflux');
const FeatureActions = require('./FeatureToggleActions');
const filter = require('lodash/collection/filter');
const sortBy = require('lodash/collection/sortBy');
2015-03-17 18:31:55 +01:00
2016-06-18 21:53:18 +02:00
let _archivedToggles = [];
2015-03-17 18:31:55 +01:00
// Creates a DataStore
2016-06-18 21:53:18 +02:00
const FeatureStore = Reflux.createStore({
2015-03-17 20:34:19 +01:00
// Initial setup
2016-06-18 21:53:18 +02:00
init() {
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);
},
2016-06-18 21:53:18 +02:00
onInit(toggles) {
2015-03-17 22:52:10 +01:00
_archivedToggles = toggles;
this.trigger();
2015-03-17 20:34:19 +01:00
},
2016-06-18 21:53:18 +02:00
onArchive(feature) {
const toggles = _archivedToggles.concat([feature]);
2015-03-17 20:34:19 +01:00
_archivedToggles = sortBy(toggles, 'name');
this.trigger();
},
2016-06-18 21:53:18 +02:00
onRevive(item) {
const newStore = filter(_archivedToggles, f => f.name !== item.name);
2015-03-17 20:34:19 +01:00
_archivedToggles = sortBy(newStore, 'name');
this.trigger();
},
2016-06-18 21:53:18 +02:00
getArchivedToggles() {
2015-03-17 20:34:19 +01:00
return _archivedToggles;
},
2016-06-18 21:53:18 +02:00
initStore(archivedToggles) {
2015-03-17 20:34:19 +01:00
_archivedToggles = archivedToggles;
2016-06-18 21:55:46 +02:00
},
2015-03-17 18:31:55 +01:00
});
module.exports = FeatureStore;