Skip to content

Commit

Permalink
chore: bump to 3.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticsoul committed Dec 16, 2023
1 parent ef61415 commit 784a9a1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 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.5",
"version": "3.5.6",
"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/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.5';
export const VER = '3.5.6';

export const LIMU_VER = limuVer;

Expand Down
8 changes: 4 additions & 4 deletions packages/helux-core/src/factory/creator/mutateFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ICallMutateBase {
interface ICallMutateFnOpt<T = SharedState> extends ICallMutateBase {
fn: Fn;
/** fn 函数调用入参拼装 */
getArgs?: (param: { draft: T; draftRoot: T; setState: Fn; desc: string; input: any[] }) => any[];
getArgs?: (param: { isFirstCall: boolean; draft: T; draftRoot: T; setState: Fn; desc: string; input: any[] }) => any[];
}

interface ICallAsyncMutateFnOpt extends ICallMutateBase {
Expand All @@ -43,7 +43,7 @@ export function callAsyncMutateFnLogic<T = SharedState>(
targetState: T,
options: ICallAsyncMutateFnOpt,
): [any, Error | null] | Promise<[any, Error | null]> {
const { desc = '', sn, task, getArgs = noop, deps, from, throwErr, depKeys } = options;
const { desc = '', sn, task, getArgs = noop, deps, from, throwErr, depKeys, isFirstCall } = options;
const internal = getInternal(targetState);
const { sharedKey } = internal;
const customOptions: IInnerSetStateOptions = { desc, sn, from };
Expand All @@ -63,7 +63,7 @@ export function callAsyncMutateFnLogic<T = SharedState>(
return finish(cb);
};

const defaultParams = { desc, setState, input: enureReturnArr(deps, targetState), draft, draftRoot, flush };
const defaultParams = { isFirstCall, desc, setState, input: enureReturnArr(deps, targetState), draft, draftRoot, flush };
const args = getArgs(defaultParams) || [defaultParams];
const isProm = fnProm.get(task);
const isUnconfirmedFn = isProm === undefined;
Expand Down Expand Up @@ -138,7 +138,7 @@ export function callMutateFnLogic<T = SharedState>(targetState: T, options: ICal
markIgnore(false); // recover dep collect
}
const { draftNode: draft, draftRoot, finish } = setStateFactory({ from, enableDep: true });
const args = getArgs({ draft, draftRoot, setState, desc, input }) || [draft, { input, state, draftRoot }];
const args = getArgs({ isFirstCall, draft, draftRoot, setState, desc, input }) || [draft, { input, state, draftRoot, isFirstCall }];

try {
const result = fn(...args);
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 @@ -59,7 +59,7 @@ import type {
WatchOptionsType,
} from './base';

export declare const VER: '3.5.5';
export declare const VER: '3.5.6';

export declare const LIMU_VER: string;

Expand Down
26 changes: 19 additions & 7 deletions packages/helux-core/src/types/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ export interface IRunMutateOptions {
}

export interface IMutateTaskParam<T = SharedState, P = any[]> {
/** 是否第一次调用 */
isFirstCall;
/** 异步任务提供的 draft 是全局响应式对象 */
draftRoot: DraftRootType<T>;
draft: DraftType<T>;
Expand Down Expand Up @@ -272,8 +274,18 @@ export type MutateTask<T = SharedState, P = ReadOnlyArr> = (param: IMutateTaskPa

/** 如定义了 task 函数,则 fn 在异步函数执行之前回执行一次,且只在首次执行一次,后续不会执行 */
export type MutateFn<T = SharedState, P = ReadOnlyArr> = (
/** 草稿状态,对与 atom 对象 draft 是已拆箱的值,如需操作未拆箱值可读取下面的 params.draftRoot */
draft: DraftType<T>,
params: { input: P; state: StateType<T>; draftRoot: DraftRootType<T> },
params: {
/** 是否第一次调用 */
isFirstCall: boolean;
/** mutate deps 函数的返回值 */
input: P;
/** 只读状态 */
state: StateType<T>;
/** 草稿根状态,对与 atom 对象,根状态是未拆箱的值 */
draftRoot: DraftRootType<T>;
},
) => void;

export type MutateFnItem<T = SharedState, P = ReadOnlyArr> = {
Expand Down Expand Up @@ -452,8 +464,8 @@ export type SyncFnBuilder<T = SharedState, V = any> = (

export type Syncer<T = SharedState> = T extends Atom | ReadOnlyAtom
? T['val'] extends Primitive
? SyncerFn
: { [key in keyof T['val']]: SyncerFn }
? SyncerFn
: { [key in keyof T['val']]: SyncerFn }
: { [key in keyof T]: SyncerFn };

export type SafeLoading<T = SharedState, O extends ICreateOptions<T> = ICreateOptions<T>> = O['mutate'] extends MutateFnDict<T>
Expand All @@ -462,16 +474,16 @@ export type SafeLoading<T = SharedState, O extends ICreateOptions<T> = ICreateOp

type FnResultType<T extends PlainObject | DeriveFn> = T extends PlainObject
? T['fn'] extends Fn
? DerivedAtom<ReturnType<T['fn']>>
: DerivedAtom<any>
? DerivedAtom<ReturnType<T['fn']>>
: DerivedAtom<any>
: T extends DeriveFn
? DerivedAtom<ReturnType<T>>
: DerivedAtom<any>;

type FnResultValType<T extends PlainObject | DeriveFn> = T extends PlainObject
? T['fn'] extends Fn
? ReturnType<T['fn']>
: any
? ReturnType<T['fn']>
: any
: T extends DeriveFn
? ReturnType<T>
: any;
Expand Down

0 comments on commit 784a9a1

Please sign in to comment.