Skip to content

Commit

Permalink
build(3.4.13): support draft collection dep
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Dec 2, 2023
1 parent 94c8e41 commit cff6979
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/helux-core/src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/helux-core/src/factory/creator/mutateDeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 13 additions & 6 deletions packages/helux-core/src/factory/creator/operateState.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down

0 comments on commit cff6979

Please sign in to comment.