Skip to content

Commit 3c16c7e

Browse files
committed
sync update code
1 parent e317116 commit 3c16c7e

File tree

3 files changed

+30
-38
lines changed

3 files changed

+30
-38
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { createStore } from "./store";
2-
export { useStore, useConciseState } from "./store/hook";
2+
export * from "./store/hook";
33
export type {
44
StoreOptions, InitialStateForbiddenKeys, State, PrimateForbiddenType, ConciseStore,
55
SetState, StateFnType, StateCallback, SyncUpdate, Restore, SetOptions, UseStore,

src/store/types.ts

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ export interface StoreOptions {
2525
readonly __useConciseStateMode__?: boolean;
2626
}
2727

28-
/** Type of key disabled in the initialization parameters */
29-
export type InitialStateForbiddenKeys =
30-
| "setState"
31-
| "syncUpdate"
32-
| "subscribe"
33-
| "restore"
34-
| "setOptions"
35-
| "useStore"
36-
| "useSubscription"
37-
| "store";
38-
3928
/**
4029
* @description Type of storeMapValue
4130
*/
@@ -55,6 +44,31 @@ export type StoreMapValueType<S extends PrimitiveState> = {
5544
updater: Callback;
5645
};
5746

47+
/** Some of the core tool method types of store */
48+
export type StoreCoreUtils<S extends PrimitiveState> = Readonly<
49+
& SetState<S>
50+
& SyncUpdate<S>
51+
& Restore<S>
52+
& Subscribe<S>
53+
& UseStore<S>
54+
& UseSubscription<S>
55+
>;
56+
57+
/** Tool method type of store */
58+
export type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & Readonly<SetOptions>;
59+
60+
/** The type of store returned by createStore */
61+
export type Store<S extends PrimitiveState> = S & StoreUtils<S>;
62+
63+
export type ConciseStoreCore<S extends PrimitiveState> = S & StoreCoreUtils<S>;
64+
65+
export interface ConciseStoreHeart<S extends PrimitiveState> {
66+
readonly store: ConciseStoreCore<S>;
67+
}
68+
69+
/** Return type of useConciseState */
70+
export type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & ConciseStoreHeart<S>;
71+
5872
export type StoreMapValue<S extends PrimitiveState> = MapType<StoreMapValueType<S>>;
5973
// Type of storeMap
6074
export type StoreMap<S extends PrimitiveState> = Map<keyof S, StoreMapValue<S>>;
@@ -182,30 +196,8 @@ export interface UseSubscription<S extends PrimitiveState> {
182196
useSubscription(listener: ListenerType<S>, stateKeys?: (keyof S)[]): void;
183197
}
184198

185-
/** Some of the core tool method types of store */
186-
export type StoreCoreUtils<S extends PrimitiveState> = Readonly<
187-
& SetState<S>
188-
& SyncUpdate<S>
189-
& Restore<S>
190-
& Subscribe<S>
191-
& UseStore<S>
192-
& UseSubscription<S>
193-
>;
194-
195-
/** Tool method type of store */
196-
export type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & Readonly<SetOptions>;
197-
198-
/** The type of store returned by createStore */
199-
export type Store<S extends PrimitiveState> = S & StoreUtils<S>;
200-
201-
export type ConciseStoreCore<S extends PrimitiveState> = S & StoreCoreUtils<S>;
202-
203-
export interface ConciseStoreHeart<S extends PrimitiveState> {
204-
readonly store: ConciseStoreCore<S>;
205-
}
206-
207-
/** Return type of useConciseState */
208-
export type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & ConciseStoreHeart<S>;
199+
/** Type of key disabled in the initialization parameters */
200+
export type InitialStateForbiddenKeys = keyof StoreUtils<PrimitiveState> | "store";
209201

210202
/** thisType type used to initialize store when initialState is a function */
211203
export type InitialStore<S extends PrimitiveState> = {

src/store/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PrimitiveState, ValueOf, MapType, Callback, AnyFn } from "../types";
22
import type {
3-
StoreMapValue, StoreMapValueType, StoreMap, InitialState,
4-
StateRefCounterMapType, State, ClassThisPointerType, StoreOptions, Store,
3+
StoreMapValue, StoreMapValueType, StoreMap, InitialState, Store,
4+
StateRefCounterMapType, State, ClassThisPointerType, StoreOptions,
55
} from "./types";
66
import type { SchedulerType } from "../scheduler/types";
77
import type { ListenerType } from "../subscribe/types";

0 commit comments

Comments
 (0)