mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
Application states should be loaded as high up as possible
This commit is contained in:
parent
d4893f87ef
commit
0c836bef36
@ -3,6 +3,9 @@ var Router = require('react-router');
|
|||||||
var Menu = require('./components/Menu');
|
var Menu = require('./components/Menu');
|
||||||
var ErrorMessages = require('./components/ErrorMessages');
|
var ErrorMessages = require('./components/ErrorMessages');
|
||||||
var initalizer = require('./stores/initalizer');
|
var initalizer = require('./stores/initalizer');
|
||||||
|
var FeatureToggleStore = require('./stores/FeatureToggleStore');
|
||||||
|
var StrategyStore = require('./stores/StrategyStore');
|
||||||
|
var ArchiveStore = require('./stores/ArchivedToggleStore');
|
||||||
var Link = Router.Link;
|
var Link = Router.Link;
|
||||||
var RouteHandler = Router.RouteHandler;
|
var RouteHandler = Router.RouteHandler;
|
||||||
|
|
||||||
@ -11,6 +14,43 @@ var UnleashApp = React.createClass({
|
|||||||
router: React.PropTypes.func
|
router: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getInitialState: function() {
|
||||||
|
return {
|
||||||
|
features: FeatureToggleStore.getFeatureToggles(),
|
||||||
|
strategies: StrategyStore.getStrategies(),
|
||||||
|
archivedFeatures: ArchiveStore.getArchivedToggles()
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
onFeatureToggleChange: function() {
|
||||||
|
this.setState({
|
||||||
|
features: FeatureToggleStore.getFeatureToggles()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onStrategiesChange: function() {
|
||||||
|
this.setState({
|
||||||
|
strategies: StrategyStore.getStrategies()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onArchiveChange: function() {
|
||||||
|
this.setState({
|
||||||
|
archivedFeatures: ArchiveStore.getArchivedToggles()
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
componentDidMount: function() {
|
||||||
|
this.unsubscribeFS = FeatureToggleStore.listen(this.onFeatureToggleChange);
|
||||||
|
this.unsubscribeSS = StrategyStore.listen(this.onStrategiesChange);
|
||||||
|
this.unsubscribeAS = ArchiveStore.listen(this.onArchiveChange);
|
||||||
|
},
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
this.unsubscribeFS();
|
||||||
|
this.unsubscribeSS();
|
||||||
|
this.unsubscribeAS();
|
||||||
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
initalizer(30);
|
initalizer(30);
|
||||||
},
|
},
|
||||||
@ -38,7 +78,11 @@ var UnleashApp = React.createClass({
|
|||||||
<div className="mod shadow mrn pan">
|
<div className="mod shadow mrn pan">
|
||||||
<div className="inner pan">
|
<div className="inner pan">
|
||||||
<div className="bd">
|
<div className="bd">
|
||||||
<RouteHandler/>
|
<RouteHandler
|
||||||
|
features={this.state.features}
|
||||||
|
strategies={this.state.strategies}
|
||||||
|
archivedFeatures={this.state.archivedFeatures}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,13 +16,8 @@ describe("FeatureForm", function () {
|
|||||||
{ name: "featureY" }
|
{ name: "featureY" }
|
||||||
];
|
];
|
||||||
|
|
||||||
Server.getArchivedFeatures.mockImplementation(function(cb) {
|
Component = TestUtils.renderIntoDocument(
|
||||||
cb(null, archivedToggles);
|
<FeatureArchive archivedFeatures={archivedToggles} />);
|
||||||
});
|
|
||||||
|
|
||||||
FeatureToggleStore.initStore(archivedToggles);
|
|
||||||
|
|
||||||
Component = TestUtils.renderIntoDocument(<FeatureArchive />);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
|
@ -1,27 +1,7 @@
|
|||||||
var React = require("react");
|
var React = require("react");
|
||||||
var FeatureActions = require('../../stores/FeatureToggleActions');
|
var FeatureActions = require('../../stores/FeatureToggleActions');
|
||||||
var FeatureToggleStore = require('../../stores/ArchivedToggleStore');
|
|
||||||
|
|
||||||
var ArchiveFeatureComponent = React.createClass({
|
var ArchiveFeatureComponent = React.createClass({
|
||||||
getInitialState: function() {
|
|
||||||
return {
|
|
||||||
archivedFeatures: FeatureToggleStore.getArchivedToggles()
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
onStoreChange: function() {
|
|
||||||
this.setState({
|
|
||||||
archivedFeatures: FeatureToggleStore.getArchivedToggles()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
componentDidMount: function() {
|
|
||||||
this.unsubscribe = FeatureToggleStore.listen(this.onStoreChange);
|
|
||||||
},
|
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
this.unsubscribe();
|
|
||||||
},
|
|
||||||
|
|
||||||
onRevive: function(item) {
|
onRevive: function(item) {
|
||||||
FeatureActions.revive.triggerPromise(item);
|
FeatureActions.revive.triggerPromise(item);
|
||||||
@ -39,7 +19,7 @@ var ArchiveFeatureComponent = React.createClass({
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{this.state.archivedFeatures.map(this.renderArchivedItem)}
|
{this.props.archivedFeatures.map(this.renderArchivedItem)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,29 +3,14 @@ var FeatureList = require('./FeatureList');
|
|||||||
var FeatureForm = require('./FeatureForm');
|
var FeatureForm = require('./FeatureForm');
|
||||||
var FeatureActions = require('../../stores/FeatureToggleActions');
|
var FeatureActions = require('../../stores/FeatureToggleActions');
|
||||||
var ErrorActions = require('../../stores/ErrorActions');
|
var ErrorActions = require('../../stores/ErrorActions');
|
||||||
var FeatureToggleStore = require('../../stores/FeatureToggleStore');
|
|
||||||
var StrategyStore = require('../../stores/StrategyStore');
|
|
||||||
|
|
||||||
var FeatureTogglesComponent = React.createClass({
|
var FeatureTogglesComponent = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
features: FeatureToggleStore.getFeatureToggles(),
|
|
||||||
createView: false
|
createView: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
onFeatureToggleChange: function() {
|
|
||||||
this.setState({
|
|
||||||
features: FeatureToggleStore.getFeatureToggles()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
componentDidMount: function() {
|
|
||||||
this.unsubscribe = FeatureToggleStore.listen(this.onFeatureToggleChange);
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
this.unsubscribe();
|
|
||||||
},
|
|
||||||
|
|
||||||
updateFeature: function (feature) {
|
updateFeature: function (feature) {
|
||||||
FeatureActions.update.triggerPromise(feature);
|
FeatureActions.update.triggerPromise(feature);
|
||||||
},
|
},
|
||||||
@ -55,13 +40,13 @@ var FeatureTogglesComponent = React.createClass({
|
|||||||
{this.state.createView ? this.renderCreateView() : this.renderCreateButton()}
|
{this.state.createView ? this.renderCreateView() : this.renderCreateButton()}
|
||||||
|
|
||||||
<FeatureList
|
<FeatureList
|
||||||
features={this.state.features}
|
features={this.props.features}
|
||||||
onFeatureChanged={this.updateFeature}
|
onFeatureChanged={this.updateFeature}
|
||||||
onFeatureArchive={this.archiveFeature}
|
onFeatureArchive={this.archiveFeature}
|
||||||
onFeatureSubmit={this.createFeature}
|
onFeatureSubmit={this.createFeature}
|
||||||
onFeatureCancel={this.cancelNewFeature}
|
onFeatureCancel={this.cancelNewFeature}
|
||||||
onNewFeature={this.newFeature}
|
onNewFeature={this.newFeature}
|
||||||
strategies={StrategyStore.getStrategies()} />
|
strategies={this.props.strategies} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -70,7 +55,7 @@ var FeatureTogglesComponent = React.createClass({
|
|||||||
return <FeatureForm
|
return <FeatureForm
|
||||||
onCancel={this.cancelNewFeature}
|
onCancel={this.cancelNewFeature}
|
||||||
onSubmit={this.createFeature}
|
onSubmit={this.createFeature}
|
||||||
strategies={StrategyStore.getStrategies()} />;
|
strategies={this.props.strategies} />;
|
||||||
},
|
},
|
||||||
|
|
||||||
renderCreateButton: function() {
|
renderCreateButton: function() {
|
||||||
|
@ -1,29 +1,15 @@
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
var StrategyList = require('./StrategyList');
|
var StrategyList = require('./StrategyList');
|
||||||
var StrategyForm = require('./StrategyForm');
|
var StrategyForm = require('./StrategyForm');
|
||||||
var StrategyStore = require('../../stores/StrategyStore');
|
|
||||||
var StrategyActions = require('../../stores/StrategyActions');
|
var StrategyActions = require('../../stores/StrategyActions');
|
||||||
|
|
||||||
var StrategiesComponent = React.createClass({
|
var StrategiesComponent = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
createView: false,
|
createView: false
|
||||||
strategies: StrategyStore.getStrategies()
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
onStoreChange: function() {
|
|
||||||
this.setState({
|
|
||||||
strategies: StrategyStore.getStrategies()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
componentDidMount: function() {
|
|
||||||
this.unsubscribe = StrategyStore.listen(this.onStoreChange);
|
|
||||||
},
|
|
||||||
componentWillUnmount: function() {
|
|
||||||
this.unsubscribe();
|
|
||||||
},
|
|
||||||
|
|
||||||
onNewStrategy: function() {
|
onNewStrategy: function() {
|
||||||
this.setState({createView: true});
|
this.setState({createView: true});
|
||||||
},
|
},
|
||||||
@ -48,7 +34,7 @@ var StrategiesComponent = React.createClass({
|
|||||||
this.renderCreateView() : this.renderCreateButton()}
|
this.renderCreateView() : this.renderCreateButton()}
|
||||||
<hr />
|
<hr />
|
||||||
<StrategyList
|
<StrategyList
|
||||||
strategies={this.state.strategies}
|
strategies={this.props.strategies}
|
||||||
onRemove={this.onRemove} />
|
onRemove={this.onRemove} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user