mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
Archived toggles in separate store
This commit is contained in:
parent
acf7445790
commit
96600c5598
@ -6,7 +6,7 @@ var React = require("react/addons");
|
||||
var TestUtils = React.addons.TestUtils;
|
||||
var FeatureArchive = require("../../../components/feature/ArchiveFeatureComponent");
|
||||
var Server = require("../../../stores/FeatureToggleServerFacade");
|
||||
var FeatureToggleStore = require("../../../stores/FeatureToggleStore");
|
||||
var FeatureToggleStore = require("../../../stores/ArchivedToggleStore");
|
||||
|
||||
describe("FeatureForm", function () {
|
||||
var Component;
|
||||
@ -20,7 +20,7 @@ describe("FeatureForm", function () {
|
||||
cb(archivedToggles);
|
||||
});
|
||||
|
||||
FeatureToggleStore.initStore([], archivedToggles);
|
||||
FeatureToggleStore.initStore(archivedToggles);
|
||||
|
||||
Component = TestUtils.renderIntoDocument(<FeatureArchive />);
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
var React = require("react");
|
||||
var FeatureActions = require('../../stores/FeatureToggleActions');
|
||||
var FeatureToggleStore = require('../../stores/FeatureToggleStore');
|
||||
var FeatureToggleStore = require('../../stores/ArchivedToggleStore');
|
||||
|
||||
var ArchiveFeatureComponent = React.createClass({
|
||||
getInitialState: function() {
|
||||
|
55
public/js/stores/ArchivedToggleStore.js
Normal file
55
public/js/stores/ArchivedToggleStore.js
Normal file
@ -0,0 +1,55 @@
|
||||
var Reflux = require('reflux');
|
||||
var FeatureActions = require('./FeatureToggleActions');
|
||||
var Timer = require('../utils/Timer');
|
||||
var Server = require('./FeatureToggleServerFacade');
|
||||
var filter = require('lodash/collection/filter');
|
||||
var sortBy = require('lodash/collection/sortBy');
|
||||
|
||||
var _archivedToggles = [];
|
||||
|
||||
// Creates a DataStore
|
||||
var FeatureStore = Reflux.createStore({
|
||||
//The store should be split in two: toggleStore && archivedToggleStore!
|
||||
|
||||
// Initial setup
|
||||
init: function() {
|
||||
this.listenTo(FeatureActions.archive.completed, this.onArchive);
|
||||
this.listenTo(FeatureActions.revive.completed, this.onRevive);
|
||||
|
||||
this.timer = new Timer(this.loadDataFromServer, 30*1000);
|
||||
this.timer.start();
|
||||
},
|
||||
|
||||
loadDataFromServer: function() {
|
||||
//TODO: this should not be part of the store!
|
||||
Server.getArchivedFeatures(function(err, archivedToggles) {
|
||||
_archivedToggles = archivedToggles;
|
||||
this.trigger();
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
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;
|
@ -6,9 +6,7 @@ var filter = require('lodash/collection/filter');
|
||||
var sortBy = require('lodash/collection/sortBy');
|
||||
var findIndex = require('lodash/array/findIndex');
|
||||
|
||||
//TODO: have archived toggles in seperate store.
|
||||
var _featureToggles = [];
|
||||
var _archivedToggles = [];
|
||||
|
||||
// Creates a DataStore
|
||||
var FeatureStore = Reflux.createStore({
|
||||
@ -31,11 +29,6 @@ var FeatureStore = Reflux.createStore({
|
||||
Server.getFeatures(function(err, featureToggles) {
|
||||
this.setToggles(featureToggles);
|
||||
}.bind(this));
|
||||
|
||||
Server.getArchivedFeatures(function(err, archivedToggles) {
|
||||
_archivedToggles = archivedToggles;
|
||||
this.trigger();
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
onCreate: function(feature) {
|
||||
@ -57,16 +50,11 @@ var FeatureStore = Reflux.createStore({
|
||||
var featureToggles = filter(_featureToggles, function(item) {
|
||||
return item.name !== feature.name;
|
||||
});
|
||||
_archivedToggles.unshift(feature);
|
||||
this.setToggles(featureToggles);
|
||||
this.trigger();
|
||||
},
|
||||
|
||||
onRevive: function(item) {
|
||||
var newStore = _archivedToggles.filter(function(f) {
|
||||
return f.name !== item.name;
|
||||
});
|
||||
_archivedToggles = newStore;
|
||||
this.setToggles(_featureToggles.concat([item]));
|
||||
this.trigger();
|
||||
},
|
||||
@ -75,13 +63,8 @@ var FeatureStore = Reflux.createStore({
|
||||
return _featureToggles;
|
||||
},
|
||||
|
||||
getArchivedToggles: function() {
|
||||
return _archivedToggles;
|
||||
},
|
||||
|
||||
initStore: function(toggles, archivedToggles) {
|
||||
initStore: function(toggles) {
|
||||
_featureToggles = toggles;
|
||||
_archivedToggles = archivedToggles;
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user