fix: 修复 form 关联的数据在地址栏, 地址栏变化不会同步的问题 (#3108)

This commit is contained in:
liaoxuezhi 2021-12-01 18:36:40 +08:00 committed by GitHub
parent ee3783a319
commit d545a5b07c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -10,7 +10,8 @@ import {
extendObject,
guid,
isObjectShallowModified,
syncDataFromSuper
syncDataFromSuper,
isSuperDataModified
} from './utils/helper';
import {dataMapping} from './utils/tpl-builtin';
import {RootStoreContext} from './WithRootStore';
@ -174,7 +175,9 @@ export function HocStoreFactory(renderer: {
}
} else if (
shouldSync === true ||
isObjectShallowModified(prevProps.data, props.data)
isObjectShallowModified(prevProps.data, props.data) ||
(props.syncSuperStore !== false &&
isSuperDataModified(props.data, prevProps.data, store))
) {
if (props.store && props.store.data === props.data) {
store.initData(

View File

@ -72,6 +72,30 @@ export function extendObject(
return obj;
}
export function isSuperDataModified(
data: any,
prevData: any,
store: IIRendererStore
) {
let keys: Array<string> = [];
if (store && store.storeType === 'FormStore') {
keys = uniq(
(store as IFormStore).items
.map(item => `${item.name}`.replace(/\..*$/, ''))
.concat(Object.keys(store.data))
);
} else {
keys = Object.keys(store.data);
}
if (Array.isArray(keys) && keys.length) {
return keys.some(key => data[key] !== prevData[key]);
}
return false;
}
export function syncDataFromSuper(
data: any,
superObject: any,