Skip to content

Commit 9873b0f

Browse files
committed
2 parents 92b5110 + 52bd8c0 commit 9873b0f

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

examples/counter/README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Redux DevTools Counter example
22

3-
## Getting Started
3+
## Running example
44

5-
1. Install dependencies: `npm i`
6-
2. Start the development server: `npm start`
5+
```
6+
git clone https://github.com/gaearon/redux-devtools.git
7+
cd redux-devtools
8+
npm install
9+
10+
cd examples/counter
11+
npm install
12+
npm start
13+
open http://localhost:3000
14+
```

src/persistState.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
export default function persistState(sessionId) {
1+
export default function persistState(sessionId, deserializer = null) {
22
if (!sessionId) {
33
return next => (...args) => next(...args);
44
}
55

6+
function deserializeState(fullState) {
7+
if (!fullState || typeof deserializer !== 'function') {
8+
return fullState;
9+
}
10+
return {
11+
...fullState,
12+
committedState: deserializer(fullState.committedState),
13+
computedStates: fullState.computedStates.map((computedState) => {
14+
return {
15+
...computedState,
16+
state: deserializer(computedState.state)
17+
};
18+
})
19+
};
20+
}
21+
622
return next => (reducer, initialState) => {
723
const key = `redux-dev-session-${sessionId}`;
824

925
let finalInitialState;
1026
try {
11-
finalInitialState = JSON.parse(localStorage.getItem(key)) || initialState;
27+
finalInitialState = deserializeState(JSON.parse(localStorage.getItem(key))) || initialState;
1228
next(reducer, initialState);
1329
} catch (e) {
1430
console.warn('Could not read debug session from localStorage:', e);

0 commit comments

Comments
 (0)