mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-10 19:56:54 +03:00
refactor deserialization in persistState
This commit is contained in:
parent
3294864b7d
commit
b4ea5c278e
|
@ -4,9 +4,6 @@ export default function persistState(sessionId, stateDeserializer = null, action
|
|||
}
|
||||
|
||||
function deserializeState(fullState) {
|
||||
if (!fullState || typeof stateDeserializer !== 'function') {
|
||||
return fullState;
|
||||
}
|
||||
return {
|
||||
...fullState,
|
||||
committedState: stateDeserializer(fullState.committedState),
|
||||
|
@ -20,9 +17,6 @@ export default function persistState(sessionId, stateDeserializer = null, action
|
|||
}
|
||||
|
||||
function deserializeActions(fullState) {
|
||||
if (!fullState || typeof actionDeserializer !== 'function') {
|
||||
return fullState;
|
||||
}
|
||||
return {
|
||||
...fullState,
|
||||
stagedActions: fullState.stagedActions.map((action) => {
|
||||
|
@ -31,12 +25,26 @@ export default function persistState(sessionId, stateDeserializer = null, action
|
|||
};
|
||||
}
|
||||
|
||||
function deserialize(fullState) {
|
||||
if (!fullState) {
|
||||
return fullState;
|
||||
}
|
||||
let deserializedState = fullState;
|
||||
if (typeof stateDeserializer === 'function') {
|
||||
deserializedState = deserializeState(deserializedState);
|
||||
}
|
||||
if (typeof actionDeserializer === 'function') {
|
||||
deserializedState = deserializeActions(deserializedState);
|
||||
}
|
||||
return deserializedState;
|
||||
}
|
||||
|
||||
return next => (reducer, initialState) => {
|
||||
const key = `redux-dev-session-${sessionId}`;
|
||||
|
||||
let finalInitialState;
|
||||
try {
|
||||
finalInitialState = deserializeActions(deserializeState(JSON.parse(localStorage.getItem(key)))) || initialState;
|
||||
finalInitialState = deserialize(JSON.parse(localStorage.getItem(key))) || initialState;
|
||||
next(reducer, initialState);
|
||||
} catch (e) {
|
||||
console.warn('Could not read debug session from localStorage:', e);
|
||||
|
|
Loading…
Reference in New Issue
Block a user