Skip to content

Commit

Permalink
chore: publish 4.2.6 see changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Feb 4, 2024
1 parent 3ee04d9 commit dc406ae
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 23 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": "4.2.4",
"version": "4.2.6",
"description": "A reactive atomic state engine for React like.",
"keywords": [],
"author": {
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 = '4.2.5';
export const VER = '4.2.6';

export const LIMU_VER = limuVer;

Expand Down
2 changes: 0 additions & 2 deletions packages/helux-core/src/factory/common/ctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export function newMutateCtx(options: ISetFactoryOpts): IMutateCtx {
sn = genRenderSN(),
isFirstCall = false,
desc = '',
onRead,
} = options;
return {
fnKey: '',
Expand All @@ -78,7 +77,6 @@ export function newMutateCtx(options: ISetFactoryOpts): IMutateCtx {
sn,
isFirstCall,
desc,
onRead,
};
}

Expand Down
1 change: 0 additions & 1 deletion packages/helux-core/src/factory/createShared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export function createSharedLogic(innerOptions: IInnerOptions, createOptions?: a
setDraft,
setEnableMutate: (enabled: boolean) => setEnableMutate(enabled, internal),
getOptions: () => getOptions(internal),
setOnReadHook: (onRead: Fn) => (internal.onRead = onRead),
defineActions: (throwErr?: boolean) => (actionDict: Dict<ActionTask>) => defineActions({ ...acCommon, actionDict }, throwErr),
defineTpActions: (throwErr?: boolean) => (actionDict: Dict<Action>) =>
defineActions({ ...acCommon, actionDict, forTp: true }, throwErr),
Expand Down
5 changes: 3 additions & 2 deletions packages/helux-core/src/factory/creator/operateState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export function handleOperate(opParams: IOperateParams, opts: { internal: TInter
// 1 减轻运行负担,
// 2 降低死循环可能性,例如在 watch 回调里调用顶层的 setState
if (mutateCtx.enableDep) {
// 支持对 draft 操作时可以收集到依赖: draft.a = draft.b + 1
// 来自实例 reactive 透传的 onRead
if (currReactive.onRead) {
// 来自顶层 reactive 透传的 onRead
currReactive.onRead(opParams);
} else {
// 支持对 draft 操作时可以收集到依赖: draft.a = draft.b + 1
if (getRunningFn().fnCtx) {
recordFnDepKeys([depKey], { sharedKey });
}
Expand All @@ -70,6 +70,7 @@ export function handleOperate(opParams: IOperateParams, opts: { internal: TInter
recordBlockDepKey([depKey]);
recordLastest(sharedKey, value, internal.sharedState, depKey, fullKeyPath);
}
internal.onRead?.(opParams);
}
}
return;
Expand Down
3 changes: 2 additions & 1 deletion packages/helux-core/src/factory/creator/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export function parseOptions(innerOptions: IInnerOptions, options: ICreateOption
const rules = options.rules || [];
const before = options.before || noop;
const mutate = options.mutate || noop;
const onRead = options.onRead || undefined;
// 后续 parseRules 步骤会转 stopArrDep stopDepth 到 stopDepInfo 上
const stopArrDep = options.stopArrDep ?? true;
const stopDepth = options.stopDepth || STOP_DEPTH;
Expand Down Expand Up @@ -210,7 +211,7 @@ export function parseOptions(innerOptions: IInnerOptions, options: ICreateOption
before,
mutate,
mutateFnDict,
onRead: null as any, // 等待 setOnReadHook 写入
onRead,
enableMutate,
stateType,
recordLoading,
Expand Down
4 changes: 2 additions & 2 deletions packages/helux-core/src/factory/creator/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export function nextTickFlush(sharedKey: number, desc?: string) {
}

function buildMeta(internal: TInternal, options: IBuildReactiveOpts) {
const { from = REACTIVE, onRead } = options;
const { finish, draftRoot } = internal.setStateFactory({ isReactive: true, from, handleCbReturn: false, enableDep: true, onRead });
const { from = REACTIVE } = options;
const { finish, draftRoot } = internal.setStateFactory({ isReactive: true, from, handleCbReturn: false, enableDep: true });
const latestMeta = newReactiveMeta(draftRoot, options, finish);
latestMeta.key = getReactiveKey();
latestMeta.sharedKey = internal.sharedKey;
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].5
| [email protected].6
| 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 @@ -68,7 +68,7 @@ import type {
} from './base';

export declare const cst: {
VER: '4.2.5';
VER: '4.2.6';
LIMU_VER: string;
EVENT_NAME: {
/** 共享状态创建时的事件 */
Expand Down
17 changes: 6 additions & 11 deletions packages/helux-core/src/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export interface IMutateTaskParam<T = SharedState, P extends Arr = Arr, E extend
/** deps 返回的结果 */
input: P;
extraBound: IBoundStateInfo<E>;
/**
/**
* 额外参数,用来传递给 mutate 的fn和task函数
*/
extraArgs?: any;
Expand Down Expand Up @@ -528,10 +528,6 @@ export interface IMutateCtx {
* 修改描述
*/
desc: string;
/**
* useReactive 透传的 onRead,方便为每个实例单独收集依赖
*/
onRead?: OnOperate;
}

export interface IInnerSetStateOptions extends ISetStateOptions {
Expand Down Expand Up @@ -560,7 +556,6 @@ export interface ISetFactoryOpts extends IInnerSetStateOptions {
* 同时也减少不必要的运行时分析性能损耗
*/
enableDep?: boolean;
onRead?: OnOperate;
}

/**
Expand Down Expand Up @@ -856,10 +851,6 @@ export interface ISharedStateCtxBase<T = any, O extends ICreateOptions<T> = ICre
mutate: <P extends Arr = Arr>(fnItem: IMutateFnLooseItem<T, P> | MutateFn<T, P>) => IMutateWitness<T>;
runMutate: (descOrOptions: string | IRunMutateOptions) => T;
runMutateTask: (descOrOptions: string | IRunMutateOptions) => T;
/**
* 配置 onRead 钩子函数
*/
setOnReadHook: (onRead: OnRead) => void;
/**
* 是否禁止 mutate 再次执行( 首次一定执行,此函数只能禁止是否再次执行 )
* ```ts
Expand Down Expand Up @@ -1255,12 +1246,16 @@ export interface ICreateOptionsFull<T = SharedState> {
* default: true,是否允许 mutate 执行,可以创建 atom 时设置,也可以中途通过 setEnableMutate 反复设置
*/
enableMutate: boolean;
/**
* 任何读行为都会触发此函数
*/
onRead: OnRead;
}

/**
* 目前api层面只暴露部分配置参数供用户查看
*/
export type CtxCreateOptions = Omit<ICreateOptionsFull, 'rules' | 'mutate' | 'before'>;
export type CtxCreateOptions = Omit<ICreateOptionsFull, 'rules' | 'mutate' | 'before' | 'onRead'>;

export interface IInnerCreateOptions<T = SharedState> extends ICreateOptionsFull<SharedState> {
forAtom: boolean;
Expand Down

0 comments on commit dc406ae

Please sign in to comment.