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
 
6
 
7
 import thunkMiddleware from 'redux-thunk'
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
 const { persistStore, persistReducer } = persist
18
 const { persistStore, persistReducer } = persist
11
 
19
 
12
 const persistConfig = {
20
 const persistConfig = {
14
     storage,
22
     storage,
15
 }
23
 }
16
 const persistedReducer = persistReducer(persistConfig, reducer)
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
 export const persistor  = persistStore(store)
26
 export const persistor  = persistStore(store)
19
 
27
 

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

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { connect } from 'react-redux'
2
 import { connect } from 'react-redux'
3
+import { bindActionCreators } from 'redux';
4
+import * as actions from '../../redux/action'
3
 import DecreaseBtn from '../../component/decreaseBtn'
5
 import DecreaseBtn from '../../component/decreaseBtn'
4
 import IncreaseBtn from '../../component/increaseBtn'
6
 import IncreaseBtn from '../../component/increaseBtn'
5
 import NowValue from '../../component/showValue'
7
 import NowValue from '../../component/showValue'
6
 import './index.less'
8
 import './index.less'
7
 
9
 
8
 class Counter extends React.Component<any, any> {
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
     public handleDecreaseCB = () => {
16
     public handleDecreaseCB = () => {
10
         let { count } = this.props
17
         let { count } = this.props
11
         this.props.saveCount({ count: --count })
18
         this.props.saveCount({ count: --count })
40
 
47
 
41
 export default connect(
48
 export default connect(
42
     (state: any) => ({ count: state.count }),
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
 )(Counter)
54
 )(Counter)