@@ -28,49 +28,56 @@ export class Field {
28
28
this . destructed = false
29
29
this . loading = false
30
30
this . errors = [ ]
31
+ this . props = { }
31
32
this . effectErrors = [ ]
32
33
this . initialized = false
33
34
this . initialize ( options )
34
35
this . initialized = true
35
36
}
36
37
37
38
initialize ( options ) {
38
- const editable = this . getEditableFromProps ( options . props )
39
39
const rules = this . getRulesFromProps ( options . props )
40
40
this . value = ! isEmpty ( options . value ) ? clone ( options . value ) : this . value
41
- this . initialValue = ! isEmpty ( options . initialValue )
42
- ? options . initialValue
43
- : ! isEmpty ( this . initialValue )
44
- ? this . initialValue
45
- : this . getInitialValueFromProps ( options . props )
46
41
this . name = ! isEmpty ( options . name ) ? options . name : this . name || ''
47
42
this . namePath = resolveFieldPath ( this . name )
48
- this . editable = ! isEmpty ( editable )
49
- ? editable
50
- : isEmpty ( this . editable )
51
- ? this . editable
52
- : this . getContextEditable ( )
43
+
53
44
this . path = resolveFieldPath (
54
45
! isEmpty ( options . path ) ? options . path : this . path || [ ]
55
46
)
56
47
this . rules = ! isEmpty ( rules ) ? rules : this . rules
57
48
this . required = hasRequired ( this . rules )
58
- this . props = ! isEmpty ( options . props )
59
- ? ! isEmpty ( this . props )
49
+
50
+ if ( isEmpty ( options . props ) ) {
51
+ this . initialValue = ! isEmpty ( options . initialValue )
52
+ ? options . initialValue
53
+ : this . initialValue
54
+ } else {
55
+ this . initialValue = ! isEmpty ( options . initialValue )
56
+ ? options . initialValue
57
+ : ! isEmpty ( this . initialValue )
58
+ ? this . initialValue
59
+ : this . getInitialValueFromProps ( options . props )
60
+ this . props = ! isEmpty ( this . props )
60
61
? { ...this . props , ...clone ( options . props ) }
61
62
: clone ( options . props )
62
- : this . props || { }
63
- if ( this . removed ) {
64
- this . removed = false
65
- this . visible = true
63
+ const editable = this . getEditableFromProps ( options . props )
64
+ this . editable = ! isEmpty ( editable ) ? editable : this . getContextEditable ( )
66
65
}
66
+
67
67
if ( ! this . initialized ) {
68
68
if ( isEmpty ( this . value ) && ! isEmpty ( this . initialValue ) ) {
69
69
this . value = clone ( this . initialValue )
70
70
this . context . setIn ( this . name , this . value )
71
71
this . context . setInitialValueIn ( this . name , this . initialValue )
72
72
}
73
73
}
74
+
75
+ if ( this . removed ) {
76
+ this . removed = false
77
+ this . visible = true
78
+ this . context . triggerEffect ( 'onFieldChange' , this . publishState ( ) )
79
+ }
80
+
74
81
if ( isFn ( options . onChange ) ) {
75
82
this . onChange ( options . onChange )
76
83
}
@@ -192,14 +199,15 @@ export class Field {
192
199
this . notify ( )
193
200
}
194
201
195
- restore ( ) {
202
+ mount ( ) {
196
203
if ( this . removed ) {
197
204
this . visible = true
198
205
this . removed = false
206
+ this . context . triggerEffect ( 'onFieldChange' , this . publishState ( ) )
199
207
}
200
208
}
201
209
202
- remove ( ) {
210
+ unmount ( ) {
203
211
this . value = undefined
204
212
this . initialValue = undefined
205
213
this . visible = false
0 commit comments