mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
Single initalizer for all stores.
This commit is contained in:
parent
97afc144d4
commit
45871ebb40
@ -3,6 +3,7 @@ var TabView = require('./components/TabView');
|
||||
var Menu = require('./components/Menu');
|
||||
var UserStore = require('./stores/UserStore');
|
||||
var ErrorMessages = require('./components/ErrorMessages');
|
||||
var initalizer = require('./stores/initalizer');
|
||||
var LogEntriesComponent = React.createFactory(require('./components/log/LogEntriesComponent'));
|
||||
var FeatureTogglesComponent = React.createFactory(require('./components/feature/FeatureTogglesComponent'));
|
||||
var StrategiesComponent = React.createFactory(require('./components/strategy/StrategiesComponent'));
|
||||
@ -35,15 +36,9 @@ var tabPanes = [
|
||||
|
||||
|
||||
var UnleashApp = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
featureToggles: [],
|
||||
archivedToggles: [],
|
||||
strategies: []
|
||||
|
||||
};
|
||||
componentWillMount: function() {
|
||||
initalizer(30);
|
||||
},
|
||||
|
||||
render: function () {
|
||||
return (
|
||||
<div>
|
||||
|
@ -1,8 +1,5 @@
|
||||
var Reflux = require('reflux');
|
||||
var FeatureActions = require('./FeatureToggleActions');
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
var Timer = require('../utils/Timer');
|
||||
var Server = require('./FeatureToggleServerFacade');
|
||||
var filter = require('lodash/collection/filter');
|
||||
var sortBy = require('lodash/collection/sortBy');
|
||||
|
||||
@ -13,26 +10,15 @@ 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);
|
||||
|
||||
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) {
|
||||
|
||||
if(err) {
|
||||
ErrorActions.error(err);
|
||||
return;
|
||||
} else {
|
||||
_archivedToggles = archivedToggles;
|
||||
this.trigger(_archivedToggles);
|
||||
}
|
||||
|
||||
}.bind(this));
|
||||
onInit: function(toggles) {
|
||||
_archivedToggles = toggles;
|
||||
this.trigger();
|
||||
},
|
||||
|
||||
onArchive: function(feature) {
|
||||
|
@ -2,12 +2,34 @@ var Reflux = require("reflux");
|
||||
var Server = require('./FeatureToggleServerFacade');
|
||||
|
||||
var FeatureToggleActions = Reflux.createActions({
|
||||
'init': { asyncResult: true },
|
||||
'initArchive':{ asyncResult: true },
|
||||
'create': { asyncResult: true },
|
||||
'update': { asyncResult: true },
|
||||
'archive': { asyncResult: true },
|
||||
'revive': { asyncResult: true }
|
||||
});
|
||||
|
||||
FeatureToggleActions.init.listen(function(){
|
||||
Server.getFeatures(function(error, features) {
|
||||
if(error) {
|
||||
this.failed(error);
|
||||
} else {
|
||||
this.completed(features);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
FeatureToggleActions.initArchive.listen(function(){
|
||||
Server.getArchivedFeatures(function(error, archivedToggles) {
|
||||
if(error) {
|
||||
this.failed(error);
|
||||
} else {
|
||||
this.completed(archivedToggles);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
FeatureToggleActions.create.listen(function(feature){
|
||||
Server.createFeature(feature, function(error) {
|
||||
if(error) {
|
||||
|
@ -1,8 +1,5 @@
|
||||
var Reflux = require('reflux');
|
||||
var FeatureActions = require('./FeatureToggleActions');
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
var Server = require('./FeatureToggleServerFacade');
|
||||
var Timer = require('../utils/Timer');
|
||||
var filter = require('lodash/collection/filter');
|
||||
var sortBy = require('lodash/collection/sortBy');
|
||||
var findIndex = require('lodash/array/findIndex');
|
||||
@ -15,26 +12,11 @@ var FeatureStore = Reflux.createStore({
|
||||
|
||||
// Initial setup
|
||||
init: function() {
|
||||
this.listenTo(FeatureActions.init.completed, this.setToggles);
|
||||
this.listenTo(FeatureActions.create.completed, this.onCreate);
|
||||
this.listenTo(FeatureActions.update.completed, this.onUpdate);
|
||||
this.listenTo(FeatureActions.archive.completed, this.onArchive);
|
||||
this.listenTo(FeatureActions.revive.completed, this.onRevive);
|
||||
|
||||
//TODO: this should not be part of the store!
|
||||
this.timer = new Timer(this.loadDataFromServer, 30*1000);
|
||||
this.timer.start();
|
||||
},
|
||||
|
||||
loadDataFromServer: function() {
|
||||
//TODO: this should not be part of the store!
|
||||
Server.getFeatures(function(err, featureToggles) {
|
||||
if(err) {
|
||||
ErrorActions.error(err);
|
||||
return;
|
||||
} else {
|
||||
this.setToggles(featureToggles);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
onCreate: function(feature) {
|
||||
|
@ -2,10 +2,21 @@ var Reflux = require("reflux");
|
||||
var StrategyAPI = require('./StrategyAPI');
|
||||
|
||||
var StrategyActions = Reflux.createActions({
|
||||
'init': { asyncResult: true },
|
||||
'create': { asyncResult: true },
|
||||
'remove': { asyncResult: true },
|
||||
});
|
||||
|
||||
StrategyActions.init.listen(function(){
|
||||
StrategyAPI.getStrategies(function(err, strategies) {
|
||||
if(err) {
|
||||
this.failed(err);
|
||||
} else {
|
||||
this.completed(strategies);
|
||||
}
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
StrategyActions.create.listen(function(feature){
|
||||
StrategyAPI.createStrategy(feature, function(err) {
|
||||
if(err) {
|
||||
|
@ -1,7 +1,5 @@
|
||||
var Reflux = require('reflux');
|
||||
var ErrorActions = require('./ErrorActions');
|
||||
var StrategyActions = require('./StrategyActions');
|
||||
var StrategyAPI = require('./StrategyAPI');
|
||||
var filter = require('lodash/collection/filter');
|
||||
|
||||
var _strategies = [];
|
||||
@ -11,22 +9,9 @@ var StrategyStore = Reflux.createStore({
|
||||
|
||||
// Initial setup
|
||||
init: function() {
|
||||
this.listenTo(StrategyActions.init.completed, this.setStrategies);
|
||||
this.listenTo(StrategyActions.create.completed, this.onCreate);
|
||||
this.listenTo(StrategyActions.remove.completed, this.onRemove);
|
||||
this.loadDataFromServer();
|
||||
},
|
||||
|
||||
loadDataFromServer: function() {
|
||||
//TODO: this should not be part of the store!
|
||||
StrategyAPI.getStrategies(function(err, strategies) {
|
||||
|
||||
if(err) {
|
||||
ErrorActions.error(err);
|
||||
return;
|
||||
} else {
|
||||
this.setStrategies(strategies);
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
onCreate: function(strategy) {
|
||||
|
17
public/js/stores/initalizer.js
Normal file
17
public/js/stores/initalizer.js
Normal file
@ -0,0 +1,17 @@
|
||||
var FeatureToggleActions = require('./FeatureToggleActions');
|
||||
var StrategyActions = require('./StrategyActions');
|
||||
var Timer = require('../utils/Timer');
|
||||
|
||||
var _timer;
|
||||
|
||||
function load() {
|
||||
FeatureToggleActions.init.triggerPromise();
|
||||
StrategyActions.init.triggerPromise();
|
||||
FeatureToggleActions.initArchive.triggerPromise();
|
||||
}
|
||||
|
||||
module.exports = function(pollInterval) {
|
||||
var intervall = pollInterval || 30;
|
||||
_timer = new Timer(load, intervall*1000);
|
||||
_timer.start();
|
||||
};
|
Loading…
Reference in New Issue
Block a user