Browse Source

修改logger

胡家华 5 years ago
parent
commit
87083358a9
2 changed files with 21 additions and 5 deletions
  1. 10 2
      src/redux/store/index.ts
  2. 11 3
      src/views/ReduxTest/index.tsx

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

@@ -6,7 +6,15 @@ import storage from 'redux-persist/lib/storage'
6 6
 
7 7
 import thunkMiddleware from 'redux-thunk'
8 8
 
9
-const loggerMiddleware = createLogger()
9
+const loggerMiddleware = createLogger({
10
+    colors: {
11
+        action: () => '#03A9F4',
12
+        error: () => '#F20404',
13
+        nextState: () => '#4CAF50',
14
+        prevState: () => '#9E9E9E',
15
+        title: () => 'inherit',
16
+      },
17
+})
10 18
 const { persistStore, persistReducer } = persist
11 19
 
12 20
 const persistConfig = {
@@ -14,6 +22,6 @@ const persistConfig = {
14 22
     storage,
15 23
 }
16 24
 const persistedReducer = persistReducer(persistConfig, reducer)
17
-export const store = createStore(persistedReducer, applyMiddleware(loggerMiddleware, thunkMiddleware))
25
+export const store = createStore(persistedReducer, applyMiddleware(thunkMiddleware, loggerMiddleware))
18 26
 export const persistor  = persistStore(store)
19 27
 

+ 11 - 3
src/views/ReduxTest/index.tsx

@@ -1,11 +1,18 @@
1 1
 import * as React from 'react'
2 2
 import { connect } from 'react-redux'
3
+import { bindActionCreators } from 'redux';
4
+import * as actions from '../../redux/action'
3 5
 import DecreaseBtn from '../../component/decreaseBtn'
4 6
 import IncreaseBtn from '../../component/increaseBtn'
5 7
 import NowValue from '../../component/showValue'
6 8
 import './index.less'
7 9
 
8 10
 class Counter extends React.Component<any, any> {
11
+    public componentDidMount () {
12
+        console.log('this.props',this.props)
13
+        let { count } = this.props
14
+        this.props.actions.saveCount(--count)
15
+    }
9 16
     public handleDecreaseCB = () => {
10 17
         let { count } = this.props
11 18
         this.props.saveCount({ count: --count })
@@ -40,7 +47,8 @@ class Counter extends React.Component<any, any> {
40 47
 
41 48
 export default connect(
42 49
     (state: any) => ({ count: state.count }),
43
-    {
44
-        saveCount: (payload: any) => ({ type: 'SAVECOUNT', payload }),
45
-    }
50
+    (dispatch: any) => ({ actions: bindActionCreators(actions, dispatch) })
51
+    // {
52
+    //     saveCount: (payload: any) => ({ type: 'SAVECOUNT', payload }),
53
+    // }
46 54
 )(Counter)