mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-29 04:53:54 +03:00
Merge pull request #78 from FredyC/persist-state-serialization
custom parsers for persistState
This commit is contained in:
commit
52bd8c0d7c
|
@ -1,14 +1,30 @@
|
||||||
export default function persistState(sessionId) {
|
export default function persistState(sessionId, deserializer = null) {
|
||||||
if (!sessionId) {
|
if (!sessionId) {
|
||||||
return next => (...args) => next(...args);
|
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) => {
|
return next => (reducer, initialState) => {
|
||||||
const key = `redux-dev-session-${sessionId}`;
|
const key = `redux-dev-session-${sessionId}`;
|
||||||
|
|
||||||
let finalInitialState;
|
let finalInitialState;
|
||||||
try {
|
try {
|
||||||
finalInitialState = JSON.parse(localStorage.getItem(key)) || initialState;
|
finalInitialState = deserializeState(JSON.parse(localStorage.getItem(key))) || initialState;
|
||||||
next(reducer, initialState);
|
next(reducer, initialState);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Could not read debug session from localStorage:', e);
|
console.warn('Could not read debug session from localStorage:', e);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user