From f01584b8374c4669cd87dbe0c0a90a0f7341f373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <645381995@qq.com> Date: Fri, 1 Dec 2023 17:52:37 +0800 Subject: [PATCH] feat: reduce --- src/components/form/utils.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/form/utils.ts b/src/components/form/utils.ts index c5fa16d2b3..9580f42513 100644 --- a/src/components/form/utils.ts +++ b/src/components/form/utils.ts @@ -30,15 +30,15 @@ export function isSafeSetRefComponent(component: any): boolean { return !isSimpleFunctionComponent(component.type) } -export function cloneByNamePathList( +export const cloneByNamePathList = ( store: Store, namePathList: NamePath[] -): Store { - let newStore = {} - namePathList.forEach(namePath => { - const value = getValue(store, toArray(namePath)) - newStore = setValue(newStore, toArray(namePath), value) - }) - - return newStore +): Store => { + return namePathList.reduce((accumulator, currentValue) => { + return setValue( + accumulator, + toArray(currentValue), + getValue(store, toArray(currentValue)) + ) + }, {}) }