mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-22 09:36:43 +03:00
Merge branch 'master' of https://github.com/gaearon/redux-devtools
This commit is contained in:
commit
9873b0f9e5
|
@ -1,6 +1,14 @@
|
|||
# Redux DevTools Counter example
|
||||
|
||||
## Getting Started
|
||||
## Running example
|
||||
|
||||
1. Install dependencies: `npm i`
|
||||
2. Start the development server: `npm start`
|
||||
```
|
||||
git clone https://github.com/gaearon/redux-devtools.git
|
||||
cd redux-devtools
|
||||
npm install
|
||||
|
||||
cd examples/counter
|
||||
npm install
|
||||
npm start
|
||||
open http://localhost:3000
|
||||
```
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user