mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-09 20:00:56 +08:00
cleanup middleware pre-ship (mostly lint) (#329)
Fixes #180 URL middleware unused, but retained in expectation that we will need it shortly. Fixed a bit of lint, mostly by reformatting or commenting out currently unused code.
This commit is contained in:
@@ -1,25 +1,31 @@
|
|||||||
// jshint esversion: 6
|
// jshint esversion: 6
|
||||||
import uri from "urijs";
|
// import uri from "urijs";
|
||||||
|
|
||||||
|
/*
|
||||||
|
NOTE: file currently not used, but retained as we expect to reinstate features in this
|
||||||
|
area shortly.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
https://medium.com/@jacobp100/you-arent-using-redux-middleware-enough-94ffe991e6
|
https://medium.com/@jacobp100/you-arent-using-redux-middleware-enough-94ffe991e6
|
||||||
storeInstance => functionToCallWithAnActionThatWillSendItToTheNextMiddleware => actionThatDispatchWasCalledWith => valueToUseAsTheReturnValueOfTheDispatchCall
|
storeInstance
|
||||||
|
=> functionToCallWithAnActionThatWillSendItToTheNextMiddleware
|
||||||
|
=> actionThatDispatchWasCalledWith
|
||||||
|
=> valueToUseAsTheReturnValueOfTheDispatchCall
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const updateURLMiddleware = store => {
|
const updateURLMiddleware = (/* store */) => next => action => {
|
||||||
return next => {
|
// const oldState = store.getState();
|
||||||
return action => {
|
const nextAction = next(action);
|
||||||
const oldState = store.getState();
|
|
||||||
const nextAction = next(action);
|
|
||||||
|
|
||||||
if (action.type === "url changed") {
|
if (action.type === "url changed") {
|
||||||
/* we don't handle pop state here - we handle it in the url reducer */
|
/* we don't handle pop state here - we handle it in the url reducer */
|
||||||
return nextAction;
|
return nextAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = store.getState();
|
// const state = store.getState();
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
*************************************************************************
|
*************************************************************************
|
||||||
1. Redux app state just changed. Clear URL, and then update it.
|
1. Redux app state just changed. Clear URL, and then update it.
|
||||||
1a. We get the whole state tree to construct the url!
|
1a. We get the whole state tree to construct the url!
|
||||||
@@ -30,54 +36,52 @@ const updateURLMiddleware = store => {
|
|||||||
*************************************************************************
|
*************************************************************************
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
// const oldURI = URI(window.location.href)
|
// const oldURI = URI(window.location.href)
|
||||||
// const newURI = URI(oldURI).setQuery({})
|
// const newURI = URI(oldURI).setQuery({})
|
||||||
|
|
||||||
// if (window.location.search === "") {
|
// if (window.location.search === "") {
|
||||||
// newURL = uri.addQuery(category, value).toString(); /* #1 */
|
// newURL = uri.addQuery(category, value).toString(); /* #1 */
|
||||||
// } 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 */
|
// } 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 */
|
||||||
// newURL = uri.removeQuery(category, value).toString(); /* #4 */
|
// newURL = uri.removeQuery(category, value).toString(); /* #4 */
|
||||||
// } else {
|
// } else {
|
||||||
// newURL = uri.addQuery(category, value).toString(); /* #2 & #3 are handled by URI */
|
// newURL = uri.addQuery(category, value).toString(); /* #2 & #3 are handled by URI */
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// window.history.pushState("", "", newURL)
|
// window.history.pushState("", "", newURL)
|
||||||
|
|
||||||
//
|
//
|
||||||
// // Internal helper for working with URIs
|
// // Internal helper for working with URIs
|
||||||
// const oldURI = new URI(window.location.href);
|
// const oldURI = new URI(window.location.href);
|
||||||
// const newURI = new URI(oldURI).setQueryData({});
|
// const newURI = new URI(oldURI).setQueryData({});
|
||||||
//
|
//
|
||||||
// newURI.setPath('/foo/bar');
|
// newURI.setPath('/foo/bar');
|
||||||
//
|
//
|
||||||
// // Set the path based on state
|
// // Set the path based on state
|
||||||
// if (!state.isOnLandingPage && state.project.id) {
|
// if (!state.isOnLandingPage && state.project.id) {
|
||||||
// newURI.setPath(newURI.getPath() + state.project.id + '/');
|
// newURI.setPath(newURI.getPath() + state.project.id + '/');
|
||||||
// newURI.addQueryData('baz', state.mode);
|
// newURI.addQueryData('baz', state.mode);
|
||||||
// newURI.addQueryData('bat', state.selection.activePageID);
|
// newURI.addQueryData('bat', state.selection.activePageID);
|
||||||
// } else {
|
// } else {
|
||||||
// newURI.setPath(newURI.getPath() + state.landingSection + '/');
|
// newURI.setPath(newURI.getPath() + state.landingSection + '/');
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // Avoid URL thrashing by replacing state while loading instead of pushing
|
// // Avoid URL thrashing by replacing state while loading instead of pushing
|
||||||
// const newPath = newURI.toString();
|
// const newPath = newURI.toString();
|
||||||
// const oldPath = oldURI.toString();
|
// const oldPath = oldURI.toString();
|
||||||
// if (newPath !== oldPath) {
|
// if (newPath !== oldPath) {
|
||||||
// if (
|
// if (
|
||||||
// (oldState.mode === 'asdf' &&
|
// (oldState.mode === 'asdf' &&
|
||||||
// state.mode === 'asdf' &&
|
// state.mode === 'asdf' &&
|
||||||
// !oldState.isOnLandingPage) ||
|
// !oldState.isOnLandingPage) ||
|
||||||
// oldState.isLoadingProject !== state.isLoadingProject
|
// oldState.isLoadingProject !== state.isLoadingProject
|
||||||
// ) {
|
// ) {
|
||||||
// window.history.replaceState(null, null, newPath);
|
// window.history.replaceState(null, null, newPath);
|
||||||
// } else {
|
// } else {
|
||||||
// window.history.pushState(null, null, newPath);
|
// window.history.pushState(null, null, newPath);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return nextAction;
|
return nextAction;
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateURLMiddleware;
|
export default updateURLMiddleware;
|
||||||
|
|||||||
Reference in New Issue
Block a user