mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-09 20:40:56 +08:00
cells reducer and middleware listen for actions
This commit is contained in:
@@ -1,47 +1,69 @@
|
|||||||
const updateURLMiddleware = store => next => action => {
|
import uri from "urijs";
|
||||||
const oldState = store.getState();
|
|
||||||
const nextAction = next(action);
|
|
||||||
|
|
||||||
console.log('middleware', store, next, action)
|
const updateURLMiddleware = (store) => {
|
||||||
|
return (next) => {
|
||||||
|
return (action) => {
|
||||||
|
const oldState = store.getState();
|
||||||
|
const nextAction = next(action);
|
||||||
|
|
||||||
if (action.type === 'url changed') {
|
if (action.type === 'url changed') {
|
||||||
return nextAction;
|
/* we don't handle pop state here - we handle it in the url reducer */
|
||||||
}
|
return nextAction;
|
||||||
|
}
|
||||||
|
|
||||||
const state = store.getState();
|
const state = store.getState();
|
||||||
|
|
||||||
// Internal helper for working with URIs
|
|
||||||
const oldURI = new URI(window.location.href);
|
|
||||||
const newURI = new URI(oldURI).setQueryData({});
|
|
||||||
|
|
||||||
newURI.setPath('/foo/bar');
|
|
||||||
|
|
||||||
// Set the path based on state
|
// const oldURI = URI(window.location.href)
|
||||||
if (!state.isOnLandingPage && state.project.id) {
|
// const newURI = URI(oldURI).setQuery({})
|
||||||
newURI.setPath(newURI.getPath() + state.project.id + '/');
|
|
||||||
newURI.addQueryData('baz', state.mode);
|
|
||||||
newURI.addQueryData('bat', state.selection.activePageID);
|
|
||||||
} else {
|
|
||||||
newURI.setPath(newURI.getPath() + state.landingSection + '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avoid URL thrashing by replacing state while loading instead of pushing
|
// if (window.location.search === "") {
|
||||||
const newPath = newURI.toString();
|
// newURL = uri.addQuery(category, value).toString(); /* #1 */
|
||||||
const oldPath = oldURI.toString();
|
// } else if (uri.hasQuery(category, value) || uri.hasQuery(category, value, true)) { /* true param here means check arrays as well http://medialize.github.io/URI.js/docs.html#search-has */
|
||||||
if (newPath !== oldPath) {
|
// newURL = uri.removeQuery(category, value).toString(); /* #4 */
|
||||||
if (
|
// } else {
|
||||||
(oldState.mode === 'asdf' &&
|
// newURL = uri.addQuery(category, value).toString(); /* #2 & #3 are handled by URI */
|
||||||
state.mode === 'asdf' &&
|
// }
|
||||||
!oldState.isOnLandingPage) ||
|
//
|
||||||
oldState.isLoadingProject !== state.isLoadingProject
|
// window.history.pushState("", "", newURL)
|
||||||
) {
|
|
||||||
window.history.replaceState(null, null, newPath);
|
|
||||||
} else {
|
//
|
||||||
window.history.pushState(null, null, newPath);
|
// // Internal helper for working with URIs
|
||||||
|
// const oldURI = new URI(window.location.href);
|
||||||
|
// const newURI = new URI(oldURI).setQueryData({});
|
||||||
|
//
|
||||||
|
// newURI.setPath('/foo/bar');
|
||||||
|
//
|
||||||
|
// // Set the path based on state
|
||||||
|
// if (!state.isOnLandingPage && state.project.id) {
|
||||||
|
// newURI.setPath(newURI.getPath() + state.project.id + '/');
|
||||||
|
// newURI.addQueryData('baz', state.mode);
|
||||||
|
// newURI.addQueryData('bat', state.selection.activePageID);
|
||||||
|
// } else {
|
||||||
|
// newURI.setPath(newURI.getPath() + state.landingSection + '/');
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Avoid URL thrashing by replacing state while loading instead of pushing
|
||||||
|
// const newPath = newURI.toString();
|
||||||
|
// const oldPath = oldURI.toString();
|
||||||
|
// if (newPath !== oldPath) {
|
||||||
|
// if (
|
||||||
|
// (oldState.mode === 'asdf' &&
|
||||||
|
// state.mode === 'asdf' &&
|
||||||
|
// !oldState.isOnLandingPage) ||
|
||||||
|
// oldState.isLoadingProject !== state.isLoadingProject
|
||||||
|
// ) {
|
||||||
|
// window.history.replaceState(null, null, newPath);
|
||||||
|
// } else {
|
||||||
|
// window.history.pushState(null, null, newPath);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
return nextAction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nextAction;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateURLMiddleware;
|
export default updateURLMiddleware;
|
||||||
|
|||||||
@@ -4,17 +4,17 @@ const Cells = (state = {
|
|||||||
error: null,
|
error: null,
|
||||||
}, action) => {
|
}, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "REQUEST_CELLS":
|
case "request cells started":
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
loading: true,
|
loading: true,
|
||||||
error: null
|
error: null
|
||||||
});
|
});
|
||||||
case "RECEIVE_CELLS":
|
case "request cells success":
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
error: null,
|
error: null,
|
||||||
cells: action.data,
|
cells: action.data,
|
||||||
});
|
});
|
||||||
case "CELLS_FETCH_ERROR":
|
case "request cells error":
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
cells: null,
|
cells: null,
|
||||||
error: action.data
|
error: action.data
|
||||||
|
|||||||
Reference in New Issue
Block a user