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