Skip to content

Commit

Permalink
perf(core): improve form change trigger performance (#3236)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jun 28, 2022
1 parent 8c90617 commit 8e8a661
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions packages/core/src/shared/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,13 @@ export const triggerFormInitialValuesChange = (
form: Form,
change: DataChange
) => {
const path = change.path
if (Array.isArray(change.object) && change.key === 'length') return
if (
contains(form.initialValues, change.object) ||
form.initialValues === change.value
) {
if (change.type === 'add' || change.type === 'set') {
patchFormValues(form, path.slice(1), change.value)
patchFormValues(form, change.path.slice(1), change.value)
}
if (form.initialized) {
form.notify(LifeCycleTypes.ON_FORM_INITIAL_VALUES_CHANGE)
Expand Down
10 changes: 7 additions & 3 deletions packages/reactive/src/tree.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { RawNode, ProxyRaw } from './environment'
import { ObservablePath, PropertyKey, IOperation } from './types'
import { PropertyKey, IOperation } from './types'
export class DataChange {
path: ObservablePath
node: DataNode
key: PropertyKey
object: object
type: string
value: any
oldValue: any
constructor(operation: IOperation, node: DataNode) {
this.node = node
this.key = operation.key
this.type = operation.type
this.object = operation.target
this.value = operation.value
this.oldValue = operation.oldValue
this.path = node.path.concat(operation.key)
}

get path() {
return this.node.path.concat(this.key)
}
}
export class DataNode {
Expand Down

0 comments on commit 8e8a661

Please sign in to comment.