Skip to content

Commit

Permalink
feat: bump 3.5.14
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Dec 16, 2023
1 parent 9b799ec commit ebf4cbb
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 17 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.5.12",
"version": "3.5.14",
"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
1 change: 1 addition & 0 deletions packages/helux-core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const { shallowCompare, isDiff } = limuUtils;
const createShared = share; // for compatible wit v2 helux
const $ = signal; // signal api alias

// user can copy this file content to build a lib that can support another react like framework
export {
atom,
atomx,
Expand Down
2 changes: 1 addition & 1 deletion packages/helux-core/src/consts/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VER as limuVer } from 'limu';

export const VER = '3.5.13';
export const VER = '3.5.14';

export const LIMU_VER = limuVer;

Expand Down
2 changes: 1 addition & 1 deletion packages/helux-core/src/factory/creator/current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function currentDraftRoot() {
export const TRIGGERED_WATCH = {
current: () => CURRENT_TRIGGERED_WATCH,
set: (val: any) => (CURRENT_TRIGGERED_WATCH = val),
del: () => 0,
del: () => CURRENT_TRIGGERED_WATCH = '',
};

export const DEPS_CB = {
Expand Down
1 change: 1 addition & 0 deletions packages/helux-core/src/factory/creator/fake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const fakeReativeMeta: IReactiveMeta = {
// { [MUTATE_FN_ITEM]: 1, fn: fnItem, deps: noopArr, oriDesc: desc, desc, depKeys: [] }
export const fakeMutateFnItem: MutateFnStdItem = {
fn: noop,
onlyDeps: false,
depKeys: [],
oriDesc: '',
desc: '',
Expand Down
14 changes: 9 additions & 5 deletions packages/helux-core/src/factory/creator/mutateFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { Fn, From, IInnerSetStateOptions, IWatchAndCallMutateDictOptions, M
import { createWatchLogic } from '../createWatch';
import { buildReactive, flushActive, innerFlush } from './reactive';

const noopAny: any = () => {};
const noopAny: any = () => { };

interface ICallMutateBase {
/** 透传给用户 */
Expand Down Expand Up @@ -155,7 +155,7 @@ export function callMutateFnLogic<T = SharedState>(targetState: T, options: ICal
finish(result, innerSetOptions);

// 存档一下收集到依赖,方便后续探测异步函数里的死循环可能存在的情况
if (isFirstCall) {
if (isFirstCall && !fnItem.onlyDeps) {
const fnCtx = getRunningFn().fnCtx;
if (fnCtx) {
// 异步函数强制忽略依赖收集行为
Expand All @@ -178,10 +178,10 @@ export function callMutateFnLogic<T = SharedState>(targetState: T, options: ICal
}
}

isMutate && TRIGGERED_WATCH.del();
TRIGGERED_WATCH.del();
return [internal.snap, null];
} catch (err: any) {
isMutate && TRIGGERED_WATCH.del();
TRIGGERED_WATCH.del();
// TODO 同步函数错误发送给插件
if (throwErr) {
throw err;
Expand All @@ -207,7 +207,7 @@ export function watchAndCallMutateDict(options: IWatchAndCallMutateDictOptions)
createWatchLogic(
({ sn, isFirstCall }) => {
flushActive();
const { desc, fn, task, immediate } = item;
const { desc, fn, task, immediate, onlyDeps } = item;
const fnCtx = getRunningFn().fnCtx;
if (isFirstCall && fnCtx) {
// 将子函数信息挂上去
Expand All @@ -216,6 +216,10 @@ export function watchAndCallMutateDict(options: IWatchAndCallMutateDictOptions)
fnCtx.checkDeadCycle = item.checkDeadCycle ?? internal.checkDeadCycle;
// 双向记录一下 fnItem 和 watch 函数之间的关系
item.watchKey = fnCtx.fnKey;
// 设定了依赖全部从 deps 函数获取
if (onlyDeps) {
item.depKeys = markFnEnd();
}
}

FN_DEP_KEYS.del();
Expand Down
3 changes: 0 additions & 3 deletions packages/helux-core/src/factory/creator/operateState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getVal, matchDictKey, nodupPush } from '@helux/utils';
import { IOperateParams } from 'limu';
import { FROM } from '../../consts';
import { recordBlockDepKey } from '../../helpers/blockDep';
import { recordFnDepKeys } from '../../helpers/fnDep';
import type { IMutateCtx, KeyIdsDict, NumStrSymbol } from '../../types/base';
Expand All @@ -12,8 +11,6 @@ import type { TInternal } from './buildInternal';
import { REACTIVE_META } from './current';
import { markExpired, nextTickFlush } from './reactive';

const { MUTATE } = FROM;

/**
* 如果变化命中了 rules[].ids 或 globaIds 规则,则添加到 mutateCtx.ids 或 globalIds 里
*/
Expand Down
4 changes: 3 additions & 1 deletion packages/helux-core/src/factory/creator/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ export function parseMutateFn(fnItem: Dict, inputDesc?: string, checkDupDict?: D
fn: fnItem,
deps: noopArr,
oriDesc: desc,
onlyDeps: false,
desc,
depKeys: [],
checkDeadCycle: undefined,
watchKey: '',
};
} else if (isObj(fnItem)) {
const { fn, desc, deps, task, immediate, checkDeadCycle } = fnItem;
const { fn, desc, deps, task, immediate, checkDeadCycle, onlyDeps = false } = fnItem;
const descVar = inputDesc || desc || '';
const fnVar = isFn(fn) ? fn : undefined;
const taskVar = isFn(task) ? task : undefined;
Expand All @@ -106,6 +107,7 @@ export function parseMutateFn(fnItem: Dict, inputDesc?: string, checkDupDict?: D
oriDesc: descVar,
deps: depsVar,
task: taskVar,
onlyDeps,
immediate,
depKeys: [],
};
Expand Down
6 changes: 3 additions & 3 deletions packages/helux-core/src/factory/creator/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function getReactiveVal(internal: TInternal, forAtom: boolean) {
return forAtom ? draft.val : draft;
}

function marUsing(rKey: string) {
function markUsing(rKey: string) {
REACTIVE_META.markUsing(rKey);
const watchFnKey = TRIGGERED_WATCH.current();
if (watchFnKey) {
Expand Down Expand Up @@ -168,14 +168,14 @@ export function buildReactive(internal: TInternal, fnDepKeys: string[], options?
[IS_ATOM]: forAtom,
};
const set = (forAtom: boolean, key: any, value: any) => {
marUsing(rKey);
markUsing(rKey);
const draftVal = getReactiveVal(internal, forAtom);
// handleOperate 里会自动触发 nextTickFlush
draftVal[key] = value;
return true;
};
const get = (forAtom: boolean, key: any, innerData: Dict) => {
marUsing(rKey);
markUsing(rKey);
const val = innerData[key];
if (val !== undefined) {
return val;
Expand Down
4 changes: 2 additions & 2 deletions packages/helux-core/src/types/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
|------------------------------------------------------------------------------------------------
| [email protected].13
| [email protected].14
| A state library core that integrates atom, signal, collection dep, derive and watch,
| it supports all react like frameworks ( including react 18 ).
|------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -59,7 +59,7 @@ import type {
WatchOptionsType,
} from './base';

export declare const VER: '3.5.13';
export declare const VER: '3.5.14';

export declare const LIMU_VER: string;

Expand Down
5 changes: 5 additions & 0 deletions packages/helux-core/src/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ export type MutateFn<T = SharedState, P = ReadOnlyArr> = (
export type MutateFnItem<T = SharedState, P = ReadOnlyArr> = {
/** 异步 mutate 的依赖项列表 */
deps?: (state: StateType<T>) => P;
/**
* defalt: false
* 依赖全部由 deps 函数提供,fn 执行过程中不收集任何依赖
*/
onlyDeps?: boolean;
/** fn 和 deps 均可以收集依赖,对应存在 task 的场景,deps 或 fn 两者保证至少有一个 */
fn?: MutateFn<T, P>;
task?: MutateTask<T, P>;
Expand Down

0 comments on commit ebf4cbb

Please sign in to comment.