Skip to content
Snippets Groups Projects
Commit b6acb3c0 authored by Tom Robinson's avatar Tom Robinson
Browse files

Remove old Angular hacks

parent 734861e7
No related branches found
No related tags found
No related merge requests found
import { createHistory } from 'history';
// An (incomplete) version of history (https://github.com/mjackson/history)
// that listens for Angular's locationChange events.
export const createAngularHistory = ($scope, $location) => {
let history = createHistory();
let angularHistory = {};
// just copy the original methods with a warning
Object.keys(history).forEach(key => {
let warned = false;
angularHistory[key] = (...args) => {
if (!warned) {
warned = true;
console.warn("createAngularHistory doesn't implement", key);
}
return history[key](...args);
};
});
angularHistory.createHref = (...args) => {
return history.createHref(...args);
}
angularHistory.replaceState = (...args) => {
return history.replaceState(...args);
}
angularHistory.listen = (listener) => {
const handler = () => {
listener({
action: "POP",
hash: $location.hash(), // window.location.hash
key: history.createKey(),
pathname: $location.path(), // window.location.pathname
query: $location.search(),
search: window.location.search,
state: null
});
};
handler();
return $scope.$on("$locationChangeSuccess", handler);
}
return angularHistory;
}
......@@ -8,7 +8,6 @@ import thunk from "redux-thunk";
import createLogger from "redux-logger";
import { createHistory } from 'history';
import { createAngularHistory } from "./createAngularHistory";
import { reduxReactRouter } from 'redux-router';
......@@ -32,21 +31,6 @@ export const createStore = compose(
window.devToolsExtension ? window.devToolsExtension() : f => f
)(originalCreateStore);
export const createStoreWithAngularScope = ($scope, $location, ...args) => {
let store = compose(
applyMiddleware(...middleware),
reduxReactRouter({ createHistory: createAngularHistory.bind(null, $scope, $location) }),
window.devToolsExtension ? window.devToolsExtension() : f => f
)(originalCreateStore)(...args);
// HACK: ugh, we have mismatched versions of redux-router and history.
// this allows hot reloading to work.
store.history.replace = ({ state, pathname, query }) =>
store.history.replaceState(state, pathname, query);
return store;
}
// HACK: just use our Angular resources for now
export function AngularResourceProxy(serviceName, methods) {
methods.forEach((methodName) => {
......@@ -108,11 +92,11 @@ export const cleanResource = (resource) => Object.keys(resource)
.reduce((map, key) => Object.assign({}, map, {[key]: resource[key]}), {});
export const fetchData = async ({
dispatch,
getState,
requestStatePath,
existingStatePath,
getData,
dispatch,
getState,
requestStatePath,
existingStatePath,
getData,
reload
}) => {
const existingData = i.getIn(getState(), existingStatePath);
......@@ -137,11 +121,11 @@ export const fetchData = async ({
}
export const updateData = async ({
dispatch,
getState,
requestStatePath,
dispatch,
getState,
requestStatePath,
existingStatePath,
// specify any request paths that need to be invalidated after this update
// specify any request paths that need to be invalidated after this update
dependentRequestStatePaths,
putData
}) => {
......@@ -162,4 +146,4 @@ export const updateData = async ({
console.error(error);
return existingData;
}
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment