Skip to content

Commit 91f8821

Browse files
update api
1 parent d9cdbcb commit 91f8821

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

packages/r-store/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ export declare function withActions<T extends Record<string, unknown>, P extends
335335
*/
336336
export declare type WithActionsProps<T, P> = {
337337
generateActions?: (state: T) => P;
338+
/**
339+
* @deprecated
340+
*
341+
* no need this option anymore
342+
*/
338343
automaticBatchAction?: boolean;
339344
};
340345

packages/r-store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reactivity-store",
3-
"version": "0.3.8",
3+
"version": "0.3.9",
44
"author": "MrWangJustToDo",
55
"license": "MIT",
66
"description": "a reactive store, make you write reactive logic in react app just like zustand",

packages/r-store/src/__test__/type.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const useCount = createState(
2929
{
3030
// withActions: (s) => ({ add: () => s.count.data++, del: () => 1 }),
3131
withPersist: "1",
32-
withNamespace: '111',
32+
withNamespace: "111",
3333
withDeepSelector: true,
3434
withStableSelector: true,
3535
}
@@ -43,7 +43,10 @@ const useFf = createStore(() => {
4343
return { vvv };
4444
});
4545

46-
const h = useFf((s) => s.vvv, (p, c) => p === c);
46+
const h = useFf(
47+
(s) => s.vvv,
48+
(p, c) => p === c
49+
);
4750

4851
const i = useCount((s) => s, Object.is);
4952

@@ -181,14 +184,14 @@ const useHH1 = createState(
181184
// // withNamespace: "1111",
182185
// }
183186
{
184-
withActions: (s) => ({add: () => s.data.push(199)}),
185-
withPersist: '111',
187+
withActions: (s) => ({ add: () => s.data.push(199) }),
188+
withPersist: "111",
186189
withDeepSelector: true,
187-
withNamespace: '2222'
190+
withNamespace: "2222",
188191
}
189192
);
190193

191-
const dd = useHH1(s => s.data);
194+
const dd = useHH1((s) => s.data);
192195

193196
useHH1.getActions();
194197

packages/r-store/src/shared/batch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { unstable_batchedUpdates } from "react-dom";
1+
const defaultBatch = (cb: () => void) => cb();
22

33
/**
44
* @internal
55
*/
6-
const batchObject: { current: (cb: () => void) => void } = { current: unstable_batchedUpdates };
6+
const batchObject: { current: (cb: () => void) => void } = { current: defaultBatch };
77

88
/**
99
* @public
@@ -29,7 +29,7 @@ export const getBatch = () => {
2929
* no need to use this function
3030
*/
3131
export const resetBatch = () => {
32-
batchObject.current = unstable_batchedUpdates;
32+
batchObject.current = defaultBatch;
3333
};
3434

3535
/**

packages/r-store/src/state/tools.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export type WithPersistProps<T extends Record<string, unknown>> = {
5858
*/
5959
export type WithActionsProps<T, P> = {
6060
generateActions?: (state: T) => P;
61+
/**
62+
* @deprecated
63+
*
64+
* no need this option anymore
65+
*/
6166
automaticBatchAction?: boolean;
6267
};
6368

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

139143
return {} as WithNamespaceProps<T>;
140144
};

0 commit comments

Comments
 (0)