Skip to content

Instantly share code, notes, and snippets.

@danyg
Created December 2, 2022 14:59
Show Gist options
  • Save danyg/27de71944bda0cbd8ae5907db9e4d732 to your computer and use it in GitHub Desktop.
Save danyg/27de71944bda0cbd8ae5907db9e4d732 to your computer and use it in GitHub Desktop.
Console REDUX DEV TOOLS [wip]
/** at the moment the idea is to use CJS chrome extension to load
this but seems to add the script after window.load so it's too late
**/
(() => {
window.__STATE_HISTORY__ = {
dispatchedActions: [],
actionAndState: []
}
const watchReducers = (reducer) => (state, action) => {
const newState = reducer(state, action)
window.__STATE_HISTORY__.dispatchedActions.push(action);
window.__STATE_HISTORY__.actionAndState.push({
action,
newState
});
return newState;
}
const watcherEnhancer = createStore => (reducer, initialState, enhancer) => createStore(watchReducers(reducer), initialState, enhancer);
function compose(...funcs) {
if (funcs.length === 0) return watcherEnhancer;
if (funcs.length === 1) return watcherEnhancer(funcs[0]);
return watcherEnhancer(funcs.reduce(
(a, b) =>
(...args) =>
a(b(...args))
))
}
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ = (arg) => {
console.log('Console Redux DevTools Engaged')
if(Array.isArray(arg)) return compose(arg);
else return compose;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment