auspice
Version:
Web app for visualizing pathogen evolution
38 lines (33 loc) • 1.06 kB
JavaScript
import * as types from "../actions/types";
import { chooseDisplayComponentFromURL } from "../actions/navigation";
import { hasExtension, getExtension } from "../util/extensions";
/* the store for cross-cutting state -- that is, state
not limited to <App>
*/
const getFirstPageToDisplay = () => {
if (hasExtension("entryPage")) {
return getExtension("entryPage");
}
return chooseDisplayComponentFromURL(window.location.pathname);
};
const general = (state = {
displayComponent: getFirstPageToDisplay(),
errorMessage: undefined,
pathname: window.location.pathname // keep a copy of what the app "thinks" the pathname is
}, action) => {
switch (action.type) {
case types.PAGE_CHANGE:
return Object.assign({}, state, {
pathname: action.path,
displayComponent: action.displayComponent,
errorMessage: action.errorMessage
});
case types.UPDATE_PATHNAME:
return Object.assign({}, state, {
pathname: action.pathname
});
default:
return state;
}
};
export default general;