mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
Merge pull request #8885 from igrowp/fix-editor-deadloop
fix: 修复页面设计器重复执行onChange的问题
This commit is contained in:
commit
05620349de
@ -530,7 +530,7 @@ export default class Form extends React.Component<FormProps, object> {
|
|||||||
reaction(
|
reaction(
|
||||||
() => store.initedAt,
|
() => store.initedAt,
|
||||||
() => {
|
() => {
|
||||||
store.inited && this.emitChange(!!this.props.submitOnChange);
|
store.inited && this.emitChange(!!this.props.submitOnChange, true);
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -1012,21 +1012,21 @@ export default class Form extends React.Component<FormProps, object> {
|
|||||||
return dispatchEvent(type, data);
|
return dispatchEvent(type, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async emitChange(submit: boolean) {
|
async emitChange(submit: boolean, skipIfNothingChanges: boolean = false) {
|
||||||
const {onChange, store, submitOnChange, dispatchEvent, data} = this.props;
|
const {onChange, store, submitOnChange, dispatchEvent, data} = this.props;
|
||||||
|
|
||||||
if (!isAlive(store)) {
|
if (!isAlive(store)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const diff = difference(store.data, store.pristine);
|
||||||
|
if (skipIfNothingChanges && !Object.keys(diff).length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 提前准备好 onChange 的参数。
|
// 提前准备好 onChange 的参数。
|
||||||
// 因为 store.data 会在 await 期间被 WithStore.componentDidUpdate 中的 store.initData 改变。导致数据丢失
|
// 因为 store.data 会在 await 期间被 WithStore.componentDidUpdate 中的 store.initData 改变。导致数据丢失
|
||||||
const changeProps = [
|
const changeProps = [store.data, diff, this.props];
|
||||||
store.data,
|
|
||||||
difference(store.data, store.pristine),
|
|
||||||
this.props
|
|
||||||
];
|
|
||||||
|
|
||||||
const dispatcher = await dispatchEvent(
|
const dispatcher = await dispatchEvent(
|
||||||
'change',
|
'change',
|
||||||
createObject(data, store.data)
|
createObject(data, store.data)
|
||||||
|
Loading…
Reference in New Issue
Block a user