From cff6979cbef22292e677fef991d3fd79a7a526f3 Mon Sep 17 00:00:00 2001 From: fantasticsoul Date: Sat, 2 Dec 2023 22:31:36 +0800 Subject: [PATCH] build(3.4.13): support draft collection dep --- package.json | 2 +- packages/helux-core/src/consts/index.ts | 2 +- .../src/factory/creator/mutateDeep.ts | 2 +- .../src/factory/creator/operateState.ts | 19 +++++++++++++------ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 1e35158b..a445d5ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "helux", - "version": "3.4.12", + "version": "3.4.13", "description": "A state library core that integrates atom, signal, collection dep, derive and watch, it supports all react like frameworks( including react 18 ).", "keywords": [], "author": { diff --git a/packages/helux-core/src/consts/index.ts b/packages/helux-core/src/consts/index.ts index 6bd08212..c69649c0 100644 --- a/packages/helux-core/src/consts/index.ts +++ b/packages/helux-core/src/consts/index.ts @@ -2,7 +2,7 @@ import { createSymbol, HAS_SYMBOL } from '../helpers/sym'; export { EVENT_NAME, FROM, LOADING_MODE } from './user'; export { HAS_SYMBOL }; -export const VER = '3.4.12'; +export const VER = '3.4.13'; export const PROD_FLAG = true; diff --git a/packages/helux-core/src/factory/creator/mutateDeep.ts b/packages/helux-core/src/factory/creator/mutateDeep.ts index e00e2ed4..89a11635 100644 --- a/packages/helux-core/src/factory/creator/mutateDeep.ts +++ b/packages/helux-core/src/factory/creator/mutateDeep.ts @@ -44,7 +44,7 @@ function handlePartial(opts: Ext<{ mutateCtx: IMutateCtx }>) { if (limuUtils.isObject(val)) { // [object Object] Object.keys(val).forEach((key) => { - draftNode[key] = val[key]; + draftNode[key] = (val as any)[key]; }); } else { draftRoot.val = val; diff --git a/packages/helux-core/src/factory/creator/operateState.ts b/packages/helux-core/src/factory/creator/operateState.ts index 57cf6130..73ecb662 100644 --- a/packages/helux-core/src/factory/creator/operateState.ts +++ b/packages/helux-core/src/factory/creator/operateState.ts @@ -1,6 +1,8 @@ import { matchDictKey, nodupPush, prefixValKey } from '@helux/utils'; import { IOperateParams } from 'limu'; +import { recordFnDepKeys } from '../../helpers/fnDep'; import type { KeyIdsDict, NumStrSymbol } from '../../types/base'; +import { getRunningFn } from '../common/fnScope'; import { cutDepKeyByStop } from '../common/stopDep'; import { getDepKeyByPath, IMutateCtx } from '../common/util'; import type { TInternal } from './buildInternal'; @@ -9,17 +11,22 @@ export function handleOperate(opParams: IOperateParams, opts: { internal: TInter const { isChange, fullKeyPath, keyPath, parentType } = opParams; const { internal, mutateCtx } = opts; const { arrKeyDict } = mutateCtx; + const { sharedKey } = internal; + if (!isChange) { + if (getRunningFn().fnCtx) { + // 支持对draft操作时可以收集到依赖: draft.a = draft.b + 1 + recordFnDepKeys([getDepKeyByPath(fullKeyPath, sharedKey)], { sharedKey }); + } if (parentType === 'Array') { - arrKeyDict[getDepKeyByPath(keyPath, internal.sharedKey)] = 1; + arrKeyDict[getDepKeyByPath(keyPath, sharedKey)] = 1; } return; } - // TODO FEATURE: 对于 limu 来说触发 set 就算变化了,如将来需要配置特性【丢弃无变化的值】, - // 可在此处扩展逻辑,如 oldVal 和 newVal 对比后相等则直接 return,不记录任何写入信息 - // const oldVal = getVal(internal.snap, fullKeyPath); - // if (opParams.value === oldVal) return; - const { moduleName, exact, sharedKey, ruleConf, level1ArrKeys } = internal; + // 对于 limu 来说触发 set 就算变化了,如将来需要配置特性【丢弃无变化的值】, + // 具体是否需要通知相关函数重执行见 notify 逻辑,里面包含了值比较过程 + + const { moduleName, exact, ruleConf, level1ArrKeys } = internal; const { writeKeyPathInfo, ids, globalIds, writeKeys } = mutateCtx; mutateCtx.level1Key = fullKeyPath[0]; mutateCtx.handleAtomCbReturn = false;