Преглед на файлове

增加异步action扩展参数

胡家华 преди 5 години
родител
ревизия
7815bd316d
променени са 2 файла, в които са добавени 5 реда и са изтрити 3 реда
  1. 1 1
      src/redux/action/index.ts
  2. 4 2
      src/redux/store/index.ts

+ 1 - 1
src/redux/action/index.ts

@@ -2,7 +2,7 @@ import * as actionType from './actionType'
2 2
 
3 3
 
4 4
 export function saveCount (value: string | number){
5
-    return (dispatch: any) => {
5
+    return (dispatch: any, getState: any, extraArgs: any) => {
6 6
         dispatch({ type: actionType.SAVECOUNT, payload: { count: value } })
7 7
     }
8 8
 }

+ 4 - 2
src/redux/store/index.ts

@@ -3,9 +3,11 @@ import { createLogger } from 'redux-logger'
3 3
 import * as persist from 'redux-persist'
4 4
 import reducer from '../reducers'
5 5
 import storage from 'redux-persist/lib/storage'
6
-
7 6
 import thunkMiddleware from 'redux-thunk'
8 7
 
8
+// 扩展参数, 可在异步action中获取到
9
+const extraArgs = 'somethings...'
10
+
9 11
 const loggerMiddleware = createLogger({
10 12
     colors: {
11 13
         action: () => '#03A9F4',
@@ -22,6 +24,6 @@ const persistConfig = {
22 24
     storage,
23 25
 }
24 26
 const persistedReducer = persistReducer(persistConfig, reducer)
25
-export const store = createStore(persistedReducer, applyMiddleware(thunkMiddleware, loggerMiddleware))
27
+export const store = createStore(persistedReducer, applyMiddleware(thunkMiddleware.withExtraArgument(extraArgs), loggerMiddleware))
26 28
 export const persistor  = persistStore(store)
27 29