From 3c16c7e7f3491e29cf10abf55f89ba25600c1532 Mon Sep 17 00:00:00 2001 From: liushanbao <1262300490@qq.com> Date: Wed, 24 Apr 2024 20:38:56 +0800 Subject: [PATCH] sync update code --- src/index.ts | 2 +- src/store/types.ts | 62 ++++++++++++++++++++------------------------- src/store/utils.tsx | 4 +-- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/index.ts b/src/index.ts index f164da8..591dfb1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, diff --git a/src/store/types.ts b/src/store/types.ts index 9d7c718..0526b93 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -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 */ @@ -55,6 +44,31 @@ export type StoreMapValueType = { updater: Callback; }; +/** Some of the core tool method types of store */ +export type StoreCoreUtils = Readonly< + & SetState + & SyncUpdate + & Restore + & Subscribe + & UseStore + & UseSubscription +>; + +/** Tool method type of store */ +export type StoreUtils = StoreCoreUtils & Readonly; + +/** The type of store returned by createStore */ +export type Store = S & StoreUtils; + +export type ConciseStoreCore = S & StoreCoreUtils; + +export interface ConciseStoreHeart { + readonly store: ConciseStoreCore; +} + +/** Return type of useConciseState */ +export type ConciseStore = S & StoreCoreUtils & ConciseStoreHeart; + export type StoreMapValue = MapType>; // Type of storeMap export type StoreMap = Map>; @@ -182,30 +196,8 @@ export interface UseSubscription { useSubscription(listener: ListenerType, stateKeys?: (keyof S)[]): void; } -/** Some of the core tool method types of store */ -export type StoreCoreUtils = Readonly< - & SetState - & SyncUpdate - & Restore - & Subscribe - & UseStore - & UseSubscription ->; - -/** Tool method type of store */ -export type StoreUtils = StoreCoreUtils & Readonly; - -/** The type of store returned by createStore */ -export type Store = S & StoreUtils; - -export type ConciseStoreCore = S & StoreCoreUtils; - -export interface ConciseStoreHeart { - readonly store: ConciseStoreCore; -} - -/** Return type of useConciseState */ -export type ConciseStore = S & StoreCoreUtils & ConciseStoreHeart; +/** Type of key disabled in the initialization parameters */ +export type InitialStateForbiddenKeys = keyof StoreUtils | "store"; /** thisType type used to initialize store when initialState is a function */ export type InitialStore = { diff --git a/src/store/utils.tsx b/src/store/utils.tsx index c6bb0e8..c46b74c 100644 --- a/src/store/utils.tsx +++ b/src/store/utils.tsx @@ -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";