mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 02:58:05 +08:00
fix: 修复页面设计器重复执行onChange的问题
This commit is contained in:
parent
76c2d1354c
commit
6cb78fe5ad
@ -530,7 +530,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||
reaction(
|
||||
() => 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);
|
||||
}
|
||||
|
||||
async emitChange(submit: boolean) {
|
||||
async emitChange(submit: boolean, skipIfNothingChanges: boolean = false) {
|
||||
const {onChange, store, submitOnChange, dispatchEvent, data} = this.props;
|
||||
|
||||
if (!isAlive(store)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const diff = difference(store.data, store.pristine);
|
||||
if (skipIfNothingChanges && !Object.keys(diff).length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 提前准备好 onChange 的参数。
|
||||
// 因为 store.data 会在 await 期间被 WithStore.componentDidUpdate 中的 store.initData 改变。导致数据丢失
|
||||
const changeProps = [
|
||||
store.data,
|
||||
difference(store.data, store.pristine),
|
||||
this.props
|
||||
];
|
||||
|
||||
const changeProps = [store.data, diff, this.props];
|
||||
const dispatcher = await dispatchEvent(
|
||||
'change',
|
||||
createObject(data, store.data)
|
||||
|
Loading…
Reference in New Issue
Block a user