From 91f88210e194594b1edb2cfb1a203d15651d0fa4 Mon Sep 17 00:00:00 2001 From: MrWangJustToDo <2711470541@qq.com> Date: Fri, 6 Dec 2024 13:24:28 +0800 Subject: [PATCH] update api --- packages/r-store/index.d.ts | 5 +++++ packages/r-store/package.json | 2 +- packages/r-store/src/__test__/type.tsx | 15 +++++++++------ packages/r-store/src/shared/batch.ts | 6 +++--- packages/r-store/src/state/tools.ts | 8 ++++++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/r-store/index.d.ts b/packages/r-store/index.d.ts index 52a0011..608773f 100644 --- a/packages/r-store/index.d.ts +++ b/packages/r-store/index.d.ts @@ -335,6 +335,11 @@ export declare function withActions, P extends */ export declare type WithActionsProps = { generateActions?: (state: T) => P; + /** + * @deprecated + * + * no need this option anymore + */ automaticBatchAction?: boolean; }; diff --git a/packages/r-store/package.json b/packages/r-store/package.json index 389978e..1267c85 100644 --- a/packages/r-store/package.json +++ b/packages/r-store/package.json @@ -1,6 +1,6 @@ { "name": "reactivity-store", - "version": "0.3.8", + "version": "0.3.9", "author": "MrWangJustToDo", "license": "MIT", "description": "a reactive store, make you write reactive logic in react app just like zustand", diff --git a/packages/r-store/src/__test__/type.tsx b/packages/r-store/src/__test__/type.tsx index a2272ba..fc83513 100644 --- a/packages/r-store/src/__test__/type.tsx +++ b/packages/r-store/src/__test__/type.tsx @@ -29,7 +29,7 @@ const useCount = createState( { // withActions: (s) => ({ add: () => s.count.data++, del: () => 1 }), withPersist: "1", - withNamespace: '111', + withNamespace: "111", withDeepSelector: true, withStableSelector: true, } @@ -43,7 +43,10 @@ const useFf = createStore(() => { return { vvv }; }); -const h = useFf((s) => s.vvv, (p, c) => p === c); +const h = useFf( + (s) => s.vvv, + (p, c) => p === c +); const i = useCount((s) => s, Object.is); @@ -181,14 +184,14 @@ const useHH1 = createState( // // withNamespace: "1111", // } { - withActions: (s) => ({add: () => s.data.push(199)}), - withPersist: '111', + withActions: (s) => ({ add: () => s.data.push(199) }), + withPersist: "111", withDeepSelector: true, - withNamespace: '2222' + withNamespace: "2222", } ); -const dd = useHH1(s => s.data); +const dd = useHH1((s) => s.data); useHH1.getActions(); diff --git a/packages/r-store/src/shared/batch.ts b/packages/r-store/src/shared/batch.ts index 536f281..cc7630c 100644 --- a/packages/r-store/src/shared/batch.ts +++ b/packages/r-store/src/shared/batch.ts @@ -1,9 +1,9 @@ -import { unstable_batchedUpdates } from "react-dom"; +const defaultBatch = (cb: () => void) => cb(); /** * @internal */ -const batchObject: { current: (cb: () => void) => void } = { current: unstable_batchedUpdates }; +const batchObject: { current: (cb: () => void) => void } = { current: defaultBatch }; /** * @public @@ -29,7 +29,7 @@ export const getBatch = () => { * no need to use this function */ export const resetBatch = () => { - batchObject.current = unstable_batchedUpdates; + batchObject.current = defaultBatch; }; /** diff --git a/packages/r-store/src/state/tools.ts b/packages/r-store/src/state/tools.ts index c59926c..622cd0b 100644 --- a/packages/r-store/src/state/tools.ts +++ b/packages/r-store/src/state/tools.ts @@ -58,6 +58,11 @@ export type WithPersistProps> = { */ export type WithActionsProps = { generateActions?: (state: T) => P; + /** + * @deprecated + * + * no need this option anymore + */ automaticBatchAction?: boolean; }; @@ -133,8 +138,7 @@ export const getFinalActions = , P extends Rec * @internal */ export const getFinalNamespace = , P extends Record>(state: MaybeStateWithMiddleware) => { - if (state["$$__state__$$"]) - return (state["$$__namespace__$$"] || {}) as WithNamespaceProps; + if (state["$$__state__$$"]) return (state["$$__namespace__$$"] || {}) as WithNamespaceProps; return {} as WithNamespaceProps; };