Skip to content

Commit

Permalink
sync update code
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbFlying committed Apr 24, 2024
1 parent e317116 commit 3c16c7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { createStore } from "./store";
export { useStore, useConciseState } from "./store/hook";
export * from "./store/hook";
export type {
StoreOptions, InitialStateForbiddenKeys, State, PrimateForbiddenType, ConciseStore,
SetState, StateFnType, StateCallback, SyncUpdate, Restore, SetOptions, UseStore,
Expand Down
62 changes: 27 additions & 35 deletions src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ export interface StoreOptions {
readonly __useConciseStateMode__?: boolean;
}

/** Type of key disabled in the initialization parameters */
export type InitialStateForbiddenKeys =
| "setState"
| "syncUpdate"
| "subscribe"
| "restore"
| "setOptions"
| "useStore"
| "useSubscription"
| "store";

/**
* @description Type of storeMapValue
*/
Expand All @@ -55,6 +44,31 @@ export type StoreMapValueType<S extends PrimitiveState> = {
updater: Callback;
};

/** Some of the core tool method types of store */
export type StoreCoreUtils<S extends PrimitiveState> = Readonly<
& SetState<S>
& SyncUpdate<S>
& Restore<S>
& Subscribe<S>
& UseStore<S>
& UseSubscription<S>
>;

/** Tool method type of store */
export type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & Readonly<SetOptions>;

/** The type of store returned by createStore */
export type Store<S extends PrimitiveState> = S & StoreUtils<S>;

export type ConciseStoreCore<S extends PrimitiveState> = S & StoreCoreUtils<S>;

export interface ConciseStoreHeart<S extends PrimitiveState> {
readonly store: ConciseStoreCore<S>;
}

/** Return type of useConciseState */
export type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & ConciseStoreHeart<S>;

export type StoreMapValue<S extends PrimitiveState> = MapType<StoreMapValueType<S>>;
// Type of storeMap
export type StoreMap<S extends PrimitiveState> = Map<keyof S, StoreMapValue<S>>;
Expand Down Expand Up @@ -182,30 +196,8 @@ export interface UseSubscription<S extends PrimitiveState> {
useSubscription(listener: ListenerType<S>, stateKeys?: (keyof S)[]): void;
}

/** Some of the core tool method types of store */
export type StoreCoreUtils<S extends PrimitiveState> = Readonly<
& SetState<S>
& SyncUpdate<S>
& Restore<S>
& Subscribe<S>
& UseStore<S>
& UseSubscription<S>
>;

/** Tool method type of store */
export type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & Readonly<SetOptions>;

/** The type of store returned by createStore */
export type Store<S extends PrimitiveState> = S & StoreUtils<S>;

export type ConciseStoreCore<S extends PrimitiveState> = S & StoreCoreUtils<S>;

export interface ConciseStoreHeart<S extends PrimitiveState> {
readonly store: ConciseStoreCore<S>;
}

/** Return type of useConciseState */
export type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & ConciseStoreHeart<S>;
/** Type of key disabled in the initialization parameters */
export type InitialStateForbiddenKeys = keyof StoreUtils<PrimitiveState> | "store";

/** thisType type used to initialize store when initialState is a function */
export type InitialStore<S extends PrimitiveState> = {
Expand Down
4 changes: 2 additions & 2 deletions src/store/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PrimitiveState, ValueOf, MapType, Callback, AnyFn } from "../types";
import type {
StoreMapValue, StoreMapValueType, StoreMap, InitialState,
StateRefCounterMapType, State, ClassThisPointerType, StoreOptions, Store,
StoreMapValue, StoreMapValueType, StoreMap, InitialState, Store,
StateRefCounterMapType, State, ClassThisPointerType, StoreOptions,
} from "./types";
import type { SchedulerType } from "../scheduler/types";
import type { ListenerType } from "../subscribe/types";
Expand Down

0 comments on commit 3c16c7e

Please sign in to comment.