File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -5,12 +5,14 @@ import { Provider } from 'redux/react';
5
5
import * as reducers from '../reducers' ;
6
6
7
7
import devTools from '../redux-devtools/index' ;
8
+ import persistState from '../redux-devtools/persistState' ;
8
9
import DebugPanel from '../redux-devtools/DebugPanel' ;
9
10
import ReduxMonitor from '../redux-devtools/ReduxMonitor' ;
10
11
11
12
const finalCreateStore = compose (
12
13
applyMiddleware ( ) ,
13
14
devTools ( ) ,
15
+ persistState ( window . location . href . match ( / [ ? & ] d e b u g _ s e s s i o n = ( [ ^ & ] + ) \b / ) ) ,
14
16
createStore
15
17
) ;
16
18
Original file line number Diff line number Diff line change
1
+ export default function persistState ( sessionId ) {
2
+ if ( ! sessionId ) {
3
+ return next => ( ...args ) => next ( ...args ) ;
4
+ }
5
+
6
+ return next => ( reducer , initialState ) => {
7
+ const key = `redux-dev-session-${ sessionId } ` ;
8
+
9
+ try {
10
+ initialState = JSON . parse ( localStorage . getItem ( key ) ) || initialState ;
11
+ next ( reducer , initialState ) ;
12
+ } catch ( e ) {
13
+ try {
14
+ localStorage . removeItem ( key ) ;
15
+ } finally {
16
+ initialState = undefined ;
17
+ }
18
+ }
19
+
20
+ const store = next ( reducer , initialState ) ;
21
+
22
+ return Object . assign ( Object . create ( store ) , {
23
+ dispatch ( action ) {
24
+ store . dispatch ( action ) ;
25
+ localStorage . setItem ( key , JSON . stringify ( store . getState ( ) ) ) ;
26
+ return action ;
27
+ }
28
+ } ) ;
29
+ } ;
30
+ }
You can’t perform that action at this time.
0 commit comments