11import * as React from 'react'
22import { 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'
55
66console . log ( store . getState ( ) , '---store' )
77
@@ -24,8 +24,7 @@ const styles = {
2424 }
2525}
2626
27-
28- export default class DemoRedux extends React . Component < IProps > {
27+ class DemoRedux extends React . Component < any > {
2928
3029
3130 add = ( ) => {
@@ -36,36 +35,56 @@ export default class DemoRedux extends React.Component<IProps> {
3635 }
3736
3837 shouldComponentUpdate ( preState : any , nextProps : any ) {
39- console . log ( preState , nextProps )
40- return false
38+ console . log ( preState , nextProps , 'shouldComponentUpdate' )
39+ return true
4140 }
4241
4342 componentDidMount ( ) {
44- console . log ( this , 'store.getState().counter' )
43+ console . log ( this . props , 'demo --- componentDidMount store.getState().counter' )
4544 }
4645
4746 render ( ) {
4847 // 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 , )
5151
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 >
7068 }
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