diff --git a/src/persistState.js b/src/persistState.js index 09a6d598..1469ab24 100644 --- a/src/persistState.js +++ b/src/persistState.js @@ -1,14 +1,30 @@ -export default function persistState(sessionId) { +export default function persistState(sessionId, deserializer = null) { if (!sessionId) { return next => (...args) => next(...args); } + function deserializeState(fullState) { + if (!fullState || typeof deserializer !== 'function') { + return fullState; + } + return { + ...fullState, + committedState: deserializer(fullState.committedState), + computedStates: fullState.computedStates.map((computedState) => { + return { + ...computedState, + state: deserializer(computedState.state) + }; + }) + }; + } + return next => (reducer, initialState) => { const key = `redux-dev-session-${sessionId}`; let finalInitialState; try { - finalInitialState = JSON.parse(localStorage.getItem(key)) || initialState; + finalInitialState = deserializeState(JSON.parse(localStorage.getItem(key))) || initialState; next(reducer, initialState); } catch (e) { console.warn('Could not read debug session from localStorage:', e);