Skip to content
This repository was archived by the owner on May 7, 2022. It is now read-only.

Commit 3befb9f

Browse files
author
yongyue.huang
committed
fix build error
1 parent 0a9d560 commit 3befb9f

File tree

10 files changed

+75
-82
lines changed

10 files changed

+75
-82
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "4.2.0",
44
"scripts": {
55
"start": "node scripts/start.js",
6-
"build": "rm -rf build && node scripts/build.js && react-snapshot",
6+
"build": "rm -rf build && node scripts/build.js",
77
"test": "node scripts/test.js --env=jsdom",
88
"serve": "serve -s build"
99
},

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { render } from 'react-snapshot'
2+
import ReactDOM from 'react-dom'
33
import { createBrowserHistory } from 'history'
44
import { createStore, applyMiddleware, compose } from 'redux'
55
import { Provider } from 'react-redux'
@@ -34,7 +34,7 @@ const store = createStore(
3434
)
3535

3636
const wrraper = Component =>
37-
render(
37+
ReactDOM.render(
3838
<Provider store={store}>
3939
<ConnectedRouter history={history}>
4040
<Component history={history} store={store}/>

src/reducers/home.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/reducers/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { combineReducers } from 'redux-immutable'
2-
import { home } from './home'
3-
import { search } from './search'
42
import { global } from './global'
3+
4+
/* your reducers */
55
const rootReducer = combineReducers({
6-
/* your reducers */
7-
home, //首页相关
8-
search, //搜索相关
96
global
107
})
118
export default rootReducer

src/reducers/search.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/utils/persistState/createSlicer.js

Whitespace-only changes.

src/utils/persistState/getSubset.js

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import createSlicer from './createSlicer.js'
2+
import mergeState from './util/mergeState.js'
3+
4+
/**
5+
* @description
6+
* persistState is a Store Enhancer that syncs (a subset of) store state to localStorage.
7+
*
8+
* @param {String|String[]} [paths] Specify keys to sync with localStorage, if left undefined the whole store is persisted
9+
* @param {Object} [config] Optional config object
10+
* @param {String} [config.key="redux"] String used as localStorage key
11+
* @param {Function} [config.slicer] (paths) => (state) => subset. A function that returns a subset
12+
* of store state that should be persisted to localStorage
13+
* @param {Function} [config.serialize=JSON.stringify] (subset) => serializedData. Called just before persisting to
14+
* localStorage. Should transform the subset into a format that can be stored.
15+
* @param {Function} [config.deserialize=JSON.parse] (persistedData) => subset. Called directly after retrieving
16+
* persistedState from localStorage. Should transform the data into the format expected by your application
17+
*
18+
* @return {Function} An enhanced store
19+
*/
20+
export default function persistState(paths, config) {
21+
const cfg = {
22+
key: 'redux',
23+
merge: mergeState,
24+
slicer: createSlicer,
25+
serialize: JSON.stringify,
26+
deserialize: JSON.parse,
27+
...config
28+
}
29+
30+
const {
31+
key,
32+
merge,
33+
slicer,
34+
serialize,
35+
deserialize
36+
} = cfg
37+
38+
return next => (reducer, initialState, enhancer) => {
39+
if (typeof initialState === 'function' && typeof enhancer === 'undefined') {
40+
enhancer = initialState
41+
initialState = undefined
42+
}
43+
44+
let persistedState
45+
let finalInitialState
46+
47+
try {
48+
persistedState = deserialize(localStorage.getItem(key))
49+
finalInitialState = merge(initialState, persistedState)
50+
} catch (e) {
51+
console.warn('Failed to retrieve initialize state from localStorage:', e)
52+
}
53+
54+
const store = next(reducer, finalInitialState, enhancer)
55+
const slicerFn = slicer(paths)
56+
57+
store.subscribe(function () {
58+
const state = store.getState()
59+
const subset = slicerFn(state)
60+
61+
try {
62+
localStorage.setItem(key, serialize(subset))
63+
} catch (e) {
64+
console.warn('Unable to persist state to localStorage:', e)
65+
}
66+
})
67+
68+
return store
69+
}
70+
}

src/utils/persistState/util/mergeState.js

Whitespace-only changes.

src/utils/persistState/util/typeOf.js

Whitespace-only changes.

0 commit comments

Comments
 (0)