1
1
import * as React from 'react'
2
2
import { Row , Col , Button , Badge , Icon , Form , Input , Select } from 'antd'
3
- import { ReduxProvider , connect } from '@ plugins/react-redux'
4
- import { store } from './reducer'
3
+ import { ReduxProvider , connect } from '../../ plugins/react-redux'
4
+ import { store , countActions } from './reducer'
5
5
6
6
console . log ( store . getState ( ) , '---store' )
7
7
@@ -24,8 +24,7 @@ const styles = {
24
24
}
25
25
}
26
26
27
-
28
- export default class DemoRedux extends React . Component < IProps > {
27
+ class DemoRedux extends React . Component < any > {
29
28
30
29
31
30
add = ( ) => {
@@ -36,36 +35,56 @@ export default class DemoRedux extends React.Component<IProps> {
36
35
}
37
36
38
37
shouldComponentUpdate ( preState : any , nextProps : any ) {
39
- console . log ( preState , nextProps )
40
- return false
38
+ console . log ( preState , nextProps , 'shouldComponentUpdate' )
39
+ return true
41
40
}
42
41
43
42
componentDidMount ( ) {
44
- console . log ( this , 'store.getState().counter' )
43
+ console . log ( this . props , 'demo --- componentDidMount store.getState().counter' )
45
44
}
46
45
47
46
render ( ) {
48
47
// const count = 9
49
- const { count } = store . getState ( ) . counter
50
- console . log ( count , ' =-===count ' )
48
+ const { counter : { count} , disabled } = this . props
49
+ const { ADD , DECREASE } = this . props
50
+ console . log ( count , 'demo render =-===count' , disabled , )
51
51
52
- return < ReduxProvider store = { store } >
53
- < div >
54
- < section style = { styles . block } >
55
- < h3 > redux测试</ h3 >
56
- < Row style = { styles . padding } >
57
- < Col span = { 24 } >
58
- < Button onClick = { this . dec } >
59
- < Icon type = "minus" />
60
- </ Button >
61
- < Badge count = { count } showZero = { true } />
62
- < Button onClick = { this . add } >
63
- < Icon type = "plus" />
64
- </ Button >
65
- </ Col >
66
- </ Row >
67
- </ section >
68
- </ div >
69
- </ ReduxProvider >
52
+ return < div >
53
+ < section style = { styles . block } >
54
+ < h3 > redux测试</ h3 >
55
+ < Row style = { styles . padding } >
56
+ < Col span = { 24 } >
57
+ < Button onClick = { DECREASE } >
58
+ < Icon type = "minus" />
59
+ </ Button >
60
+ < Badge count = { count } showZero = { true } />
61
+ < Button onClick = { ADD } >
62
+ < Icon type = "plus" />
63
+ </ Button >
64
+ </ Col >
65
+ </ Row >
66
+ </ section >
67
+ </ div >
70
68
}
71
- }
69
+ }
70
+
71
+
72
+ const DemosComponentWithRedux = connect (
73
+ ( state : any ) => ( {
74
+ counter : state . counter ,
75
+ disabled : state . counter . count > 10
76
+ } ) ,
77
+ ( dispatch : Function ) => ( {
78
+ ADD : ( ) => dispatch ( countActions . ADD ) ,
79
+ DECREASE : ( ) => dispatch ( countActions . DECREASE )
80
+ } )
81
+ ) ( DemoRedux )
82
+
83
+
84
+ const ProviderComponent : React . FC = ( ) => {
85
+ return < ReduxProvider store = { store } >
86
+ < DemosComponentWithRedux />
87
+ </ ReduxProvider >
88
+ }
89
+
90
+ export default ProviderComponent
0 commit comments