From d545a5b07ce3b3e7ae98f3a128eacfb0a66a37e4 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Wed, 1 Dec 2021 18:36:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20form=20=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=9A=84=E6=95=B0=E6=8D=AE=E5=9C=A8=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E6=A0=8F,=20=E5=9C=B0=E5=9D=80=E6=A0=8F=E5=8F=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E5=90=8C=E6=AD=A5=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#3108)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WithStore.tsx | 7 +++++-- src/utils/helper.ts | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/WithStore.tsx b/src/WithStore.tsx index 7aae74522..a2e9decc7 100644 --- a/src/WithStore.tsx +++ b/src/WithStore.tsx @@ -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( diff --git a/src/utils/helper.ts b/src/utils/helper.ts index b6fc1c815..aaa509d4f 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -72,6 +72,30 @@ export function extendObject( return obj; } +export function isSuperDataModified( + data: any, + prevData: any, + store: IIRendererStore +) { + let keys: Array = []; + + 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,