Skip to content

Commit

Permalink
feat(core): support enableUnmountRemoveNode/disableUnmountRemoveNode API
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 17, 2020
1 parent 4f6e818 commit 8f99e5b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/core/src/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const createFormExternals = (
supportUnmountClearStates,
disableUnmountClearStates,
enableUnmountClearStates,
enableUnmountRemoveNode,
disableUnmountRemoveNode,
resetFormMessages,
syncFormMessages,
batchRunTaskQueue,
Expand Down Expand Up @@ -295,6 +297,9 @@ export const createFormExternals = (
env.realRemoveTags = []
})
heart.publish(LifeCycleTypes.ON_FIELD_UNMOUNT, field)
if (env.unmountRemoveNode) {
graph.remove(field.state.path)
}
}

if (dirtys.mounted && published.mounted) {
Expand Down Expand Up @@ -363,6 +368,9 @@ export const createFormExternals = (
env.realRemoveTags = []
})
heart.publish(LifeCycleTypes.ON_FIELD_UNMOUNT, field)
if (env.unmountRemoveNode) {
graph.remove(field.state.path)
}
}
if (dirtys.mounted && published.mounted) {
heart.publish(LifeCycleTypes.ON_FIELD_MOUNT, field)
Expand Down Expand Up @@ -1143,6 +1151,8 @@ export const createFormExternals = (
getFieldInitialValue,
disableUnmountClearStates,
enableUnmountClearStates,
enableUnmountRemoveNode,
disableUnmountRemoveNode,
isHostRendering,
hostUpdate,
subscribe,
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ export const createFormInternals = (options: IFormCreatorOptions = {}) => {
env.clearStatesPatterns[path.toString()] = true
}

function disableUnmountRemoveNode() {
env.unmountRemoveNode = false
}

function enableUnmountRemoveNode() {
env.unmountRemoveNode = true
}

function supportUnmountClearStates(path: FormPathPattern) {
for (const pattern in env.clearStatesPatterns) {
const enable = env.clearStatesPatterns[pattern]
Expand Down Expand Up @@ -409,6 +417,7 @@ export const createFormInternals = (options: IFormCreatorOptions = {}) => {
realRemoveTags: [],
lastShownStates: {},
clearStatesPatterns: {},
unmountRemoveNode: false,
submittingTask: undefined
}
form.subscription = {
Expand Down Expand Up @@ -437,6 +446,8 @@ export const createFormInternals = (options: IFormCreatorOptions = {}) => {
disableUnmountClearStates,
enableUnmountClearStates,
supportUnmountClearStates,
enableUnmountRemoveNode,
disableUnmountRemoveNode,
resetFormMessages,
syncFormMessages,
batchRunTaskQueue,
Expand Down
8 changes: 6 additions & 2 deletions packages/react/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const createFormActions = (): IFormActions => {
'setFieldInitialValue',
'getFieldInitialValue',
'disableUnmountClearStates',
'enableUnmountClearStates'
'enableUnmountClearStates',
'enableUnmountRemoveNode',
'disableUnmountRemoveNode'
) as IFormActions
}

Expand Down Expand Up @@ -84,7 +86,9 @@ export const createAsyncFormActions = (): IFormAsyncActions =>
'setFieldInitialValue',
'getFieldInitialValue',
'disableUnmountClearStates',
'enableUnmountClearStates'
'enableUnmountClearStates',
'enableUnmountRemoveNode',
'disableUnmountRemoveNode'
) as IFormAsyncActions

export interface IEventTargetOption {
Expand Down

0 comments on commit 8f99e5b

Please sign in to comment.