Skip to content

Commit

Permalink
Use explicit States checks
Browse files Browse the repository at this point in the history
Refactor the States checks to explicitly compare the constants instead
of relying on the correct const  value.
  • Loading branch information
Orlando Hohmeier committed Feb 9, 2016
1 parent afa625d commit 0ceb1fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/js/components/Marathon.jsx
Expand Up @@ -59,7 +59,9 @@ var Marathon = React.createClass({
},

onPluginStoreChange: function () {
if (PluginStore.getPluginLoadingState() > States.STATE_LOADING) {
var pluginLoadingState = PluginStore.getPluginLoadingState();
if (pluginLoadingState !== States.STATE_INITIAL &&
pluginLoadingState !== States.STATE_LOADING) {
this.startPolling();
}
},
Expand Down
35 changes: 34 additions & 1 deletion src/js/stores/PluginStore.js
Expand Up @@ -51,7 +51,40 @@ var PluginStore = Object.assign({
}

return plugins.map((plugin) => plugin.state)
.reduce(Math.min);
.reduce((pluginAState, pluginBState) => {
if (pluginAState === States.STATE_INITIAL ||
pluginBState === States.STATE_INITIAL) {
return States.STATE_INITIAL;
}

if (pluginAState === States.STATE_LOADING ||
pluginBState === States.STATE_LOADING) {
return States.STATE_LOADING;
}

if (pluginAState === States.STATE_ERROR ||
pluginBState === States.STATE_ERROR) {
return States.STATE_ERROR;
}

if (pluginAState === States.STATE_UNAUTHORIZED ||
pluginBState === States.STATE_UNAUTHORIZED) {
return States.STATE_UNAUTHORIZED;
}

if (pluginAState === States.STATE_FORBIDDEN ||
pluginBState === States.STATE_FORBIDDEN) {
return States.STATE_FORBIDDEN;
}

if (pluginAState === States.STATE_SUCCESS &&
pluginBState === States.STATE_SUCCESS) {
return States.STATE_SUCCESS;
}

return States.STATE_INITIAL;

});
},
resetStore: function () {
plugins = [];
Expand Down

0 comments on commit 0ceb1fd

Please sign in to comment.