Skip to content

Commit

Permalink
fix(core): untracked update values
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Mar 14, 2021
1 parent ee870cf commit 4b54d37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/guide/scenes/login-register.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ export default () => {
/>
<SchemaField.String
name="old_password"
title="旧密码"
title="原始密码"
required
x-decorator="FormItem"
x-component="Password"
Expand Down Expand Up @@ -1307,7 +1307,7 @@ const schema = {
},
oldPassword: {
type: 'string',
title: '旧密码',
title: '原始密码',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Password',
Expand Down
33 changes: 21 additions & 12 deletions packages/core/src/models/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
toJS,
isObservable,
observe,
untracked,
} from '@formily/reactive'
import {
FormPath,
Expand Down Expand Up @@ -361,30 +362,38 @@ export class Form<ValueType extends object = any> {
/** 状态操作模型 **/

setValues = (values: any, strategy: 'overwrite' | 'merge' = 'merge') => {
if (strategy === 'merge') {
this.values = defaults(this.values, values)
} else {
this.values = values
}
untracked(() => {
if (strategy === 'merge') {
this.values = defaults(this.values, values)
} else {
this.values = values
}
})
}

setInitialValues = (
initialValues: any,
strategy: 'overwrite' | 'merge' = 'merge'
) => {
if (strategy === 'merge') {
this.initialValues = defaults(this.initialValues, initialValues)
} else {
this.initialValues = initialValues
}
untracked(() => {
if (strategy === 'merge') {
this.initialValues = defaults(this.initialValues, initialValues)
} else {
this.initialValues = initialValues
}
})
}

setValuesIn = (pattern: FormPathPattern, value: any) => {
FormPath.setIn(this.values, pattern, value)
untracked(() => {
FormPath.setIn(this.values, pattern, value)
})
}

deleteValuesIn = (pattern: FormPathPattern) => {
FormPath.deleteIn(this.values, pattern)
untracked(() => {
FormPath.deleteIn(this.values, pattern)
})
}

existValuesIn = (pattern: FormPathPattern) => {
Expand Down

0 comments on commit 4b54d37

Please sign in to comment.