1
- import * as React from 'react' ;
2
1
import warning from 'rc-util/lib/warning' ;
2
+ import * as React from 'react' ;
3
+ import { HOOK_MARK } from './FieldContext' ;
3
4
import type {
4
5
Callbacks ,
5
6
FieldData ,
6
7
FieldEntity ,
7
8
FieldError ,
8
- InternalNamePath ,
9
+ FormInstance ,
10
+ InternalFieldData ,
11
+ InternalFormInstance ,
9
12
InternalHooks ,
13
+ InternalNamePath ,
14
+ InternalValidateFields ,
15
+ Meta ,
10
16
NamePath ,
11
17
NotifyInfo ,
18
+ RuleError ,
12
19
Store ,
13
- ValidateOptions ,
14
- FormInstance ,
15
- ValidateMessages ,
16
- InternalValidateFields ,
17
- InternalFormInstance ,
18
- ValidateErrorEntity ,
19
20
StoreValue ,
20
- Meta ,
21
- InternalFieldData ,
21
+ ValidateErrorEntity ,
22
+ ValidateMessages ,
23
+ ValidateOptions ,
22
24
ValuedNotifyInfo ,
23
- RuleError ,
24
25
WatchCallBack ,
25
26
} from './interface' ;
26
- import { HOOK_MARK } from './FieldContext' ;
27
27
import { allPromiseFinish } from './utils/asyncUtil' ;
28
- import NameMap from './utils/NameMap ' ;
28
+ import cloneDeep from './utils/cloneDeep ' ;
29
29
import { defaultValidateMessages } from './utils/messages' ;
30
+ import NameMap from './utils/NameMap' ;
30
31
import {
31
32
cloneByNamePathList ,
32
33
containsNamePath ,
@@ -36,7 +37,6 @@ import {
36
37
setValue ,
37
38
setValues ,
38
39
} from './utils/valueUtil' ;
39
- import cloneDeep from './utils/cloneDeep' ;
40
40
41
41
type InvalidateFieldEntity = { INVALIDATE_NAME_PATH : InternalNamePath } ;
42
42
@@ -157,7 +157,7 @@ export class FormStore {
157
157
private destroyForm = ( ) => {
158
158
const prevWithoutPreserves = new NameMap < boolean > ( ) ;
159
159
this . getFieldEntities ( true ) . forEach ( entity => {
160
- if ( ! entity . isPreserve ( ) ) {
160
+ if ( ! this . isMergedPreserve ( entity . isPreserve ( ) ) ) {
161
161
prevWithoutPreserves . set ( entity . getNamePath ( ) , true ) ;
162
162
}
163
163
} ) ;
@@ -604,6 +604,11 @@ export class FormStore {
604
604
}
605
605
} ;
606
606
607
+ private isMergedPreserve = ( fieldPreserve ?: boolean ) => {
608
+ const mergedPreserve = fieldPreserve !== undefined ? fieldPreserve : this . preserve ;
609
+ return mergedPreserve ?? true ;
610
+ } ;
611
+
607
612
private registerField = ( entity : FieldEntity ) => {
608
613
this . fieldEntities . push ( entity ) ;
609
614
const namePath = entity . getNamePath ( ) ;
@@ -622,10 +627,9 @@ export class FormStore {
622
627
// un-register field callback
623
628
return ( isListField ?: boolean , preserve ?: boolean , subNamePath : InternalNamePath = [ ] ) => {
624
629
this . fieldEntities = this . fieldEntities . filter ( item => item !== entity ) ;
625
- // Clean up store value if not preserve
626
- const mergedPreserve = preserve !== undefined ? preserve : this . preserve ;
627
630
628
- if ( mergedPreserve === false && ( ! isListField || subNamePath . length > 1 ) ) {
631
+ // Clean up store value if not preserve
632
+ if ( ! this . isMergedPreserve ( preserve ) && ( ! isListField || subNamePath . length > 1 ) ) {
629
633
const defaultValue = isListField ? undefined : this . getInitialValue ( namePath ) ;
630
634
631
635
if (
0 commit comments