Skip to content

Commit

Permalink
update api
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWangJustToDo committed Dec 6, 2024
1 parent d9cdbcb commit 91f8821
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions packages/r-store/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ export declare function withActions<T extends Record<string, unknown>, P extends
*/
export declare type WithActionsProps<T, P> = {
generateActions?: (state: T) => P;
/**
* @deprecated
*
* no need this option anymore
*/
automaticBatchAction?: boolean;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/r-store/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 9 additions & 6 deletions packages/r-store/src/__test__/type.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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);

Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions packages/r-store/src/shared/batch.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -29,7 +29,7 @@ export const getBatch = () => {
* no need to use this function
*/
export const resetBatch = () => {
batchObject.current = unstable_batchedUpdates;
batchObject.current = defaultBatch;
};

/**
Expand Down
8 changes: 6 additions & 2 deletions packages/r-store/src/state/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export type WithPersistProps<T extends Record<string, unknown>> = {
*/
export type WithActionsProps<T, P> = {
generateActions?: (state: T) => P;
/**
* @deprecated
*
* no need this option anymore
*/
automaticBatchAction?: boolean;
};

Expand Down Expand Up @@ -133,8 +138,7 @@ export const getFinalActions = <T extends Record<string, unknown>, P extends Rec
* @internal
*/
export const getFinalNamespace = <T extends Record<string, unknown>, P extends Record<string, Function>>(state: MaybeStateWithMiddleware<T, P>) => {
if (state["$$__state__$$"])
return (state["$$__namespace__$$"] || {}) as WithNamespaceProps<T>;
if (state["$$__state__$$"]) return (state["$$__namespace__$$"] || {}) as WithNamespaceProps<T>;

return {} as WithNamespaceProps<T>;
};
Expand Down

0 comments on commit 91f8821

Please sign in to comment.