@@ -8,48 +8,61 @@ import { sequenceEventActions } from '../utils/sequence';
8
8
import actions from '../actions' ;
9
9
10
10
function mapStateToProps ( state , props ) {
11
- const { model, controlProps, mapProps } = props ;
11
+ const { model, mapProps } = props ;
12
+
13
+ if ( ! mapProps ) return props ;
14
+
12
15
const modelString = typeof model === 'function'
13
16
? model ( state )
14
17
: model ;
15
18
const fieldValue = getFieldFromState ( state , modelString ) ;
16
19
17
- if ( ! mapProps ) {
18
- return {
19
- ...props ,
20
- fieldValue,
21
- } ;
22
- }
23
-
24
- return mapProps ( {
20
+ return {
25
21
model,
26
22
modelValue : _get ( state , modelString ) ,
27
23
fieldValue,
28
- ...props ,
29
- ...controlProps ,
30
- ...sequenceEventActions ( props ) ,
31
- } ) ;
24
+ } ;
32
25
}
33
26
34
27
class Control extends Component {
35
28
constructor ( props ) {
36
29
super ( props ) ;
37
30
31
+ const { controlProps, mapProps } = props ;
32
+
38
33
this . handleKeyPress = this . handleKeyPress . bind ( this ) ;
39
34
40
35
this . state = {
41
36
value : props . modelValue ,
37
+ mappedProps : mapProps ( {
38
+ ...props ,
39
+ ...controlProps ,
40
+ ...sequenceEventActions ( props ) ,
41
+ } ) ,
42
42
} ;
43
43
}
44
44
45
45
componentWillMount ( ) {
46
- const { onLoad, modelValue } = this . props ;
46
+ const { modelValue } = this . props ;
47
+ const { onLoad } = this . state . mappedProps ;
47
48
48
49
if ( onLoad ) {
49
50
onLoad ( modelValue ) ;
50
51
}
51
52
}
52
53
54
+ componentWillReceiveProps ( nextProps ) {
55
+ const { mapProps } = nextProps ;
56
+
57
+ this . setState ( {
58
+ mappedProps : mapProps ( {
59
+ ...nextProps ,
60
+ ...nextProps . controlProps ,
61
+ ...sequenceEventActions ( nextProps ) ,
62
+ } ) ,
63
+ } ) ;
64
+ }
65
+
53
66
componentDidUpdate ( prevProps ) {
54
67
const {
55
68
modelValue,
@@ -67,7 +80,7 @@ class Control extends Component {
67
80
}
68
81
69
82
handleKeyPress ( event ) {
70
- const { onSubmit } = this . props ;
83
+ const { onSubmit } = this . state . mappedProps ;
71
84
72
85
if ( onSubmit && event . key === 'Enter' ) {
73
86
onSubmit ( event ) ;
@@ -107,7 +120,7 @@ class Control extends Component {
107
120
return cloneElement (
108
121
control ,
109
122
{
110
- ...this . props ,
123
+ ...this . state . mappedProps ,
111
124
onKeyPress : this . handleKeyPress ,
112
125
} ) ;
113
126
}
@@ -116,7 +129,7 @@ class Control extends Component {
116
129
component ,
117
130
{
118
131
...controlProps ,
119
- ...this . props ,
132
+ ...this . state . mappedProps ,
120
133
onKeyPress : this . handleKeyPress ,
121
134
} ,
122
135
controlProps . children ) ;
0 commit comments