🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

resy

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resy - npm Package Compare versions

Comparing version
11.0.0-rc.0
to
11.0.0-rc.1
+10
-10
package.json
{
"name": "resy",
"version": "11.0.0-rc.0",
"version": "11.0.0-rc.1",
"description": "React State Easy",

@@ -39,11 +39,11 @@ "repository": "https://github.com/lsbFlying/resy.git",

"import": {
"types": "./dist/esm/resy.d.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"module": {
"types": "./dist/esm/resy.d.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/esm/resy.d.ts",
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"

@@ -54,11 +54,11 @@ }

"import": {
"types": "./dist/umd/resy.d.ts",
"types": "./dist/umd/index.d.ts",
"default": "./dist/umd/index.js"
},
"module": {
"types": "./dist/umd/resy.d.ts",
"types": "./dist/umd/index.d.ts",
"default": "./dist/umd/index.js"
},
"default": {
"types": "./dist/umd/resy.d.ts",
"types": "./dist/umd/index.d.ts",
"default": "./dist/umd/index.js"

@@ -69,11 +69,11 @@ }

"import": {
"types": "./dist/system/resy.d.ts",
"types": "./dist/system/index.d.ts",
"default": "./dist/system/index.js"
},
"module": {
"types": "./dist/system/resy.d.ts",
"types": "./dist/system/index.d.ts",
"default": "./dist/system/index.js"
},
"default": {
"types": "./dist/system/resy.d.ts",
"types": "./dist/system/index.d.ts",
"default": "./dist/system/index.js"

@@ -80,0 +80,0 @@ }

/**
* resy
* An easy-to-use React data state manager
* created by liushanbao <1262300490@qq.com>
* (c) 2020-05-05-2024-3-02
* Released under the MIT License.
*/
import { Component, PureComponent } from 'react';
type Callback = () => void;
type PrimitiveState = Record<number | string, any>;
type AnyFn = (...args: unknown[]) => unknown;
type ValueOf<S extends PrimitiveState> = S[keyof S];
type MapType<S extends PrimitiveState> = Map<keyof S, ValueOf<S>>;
type NativeDataType = "Number" | "String" | "Boolean" | "Undefined" | "Null" | "Symbol" | "Object" | "Function" | "Array" | "Date" | "RegExp" | "Map" | "Set" | "WeakMap" | "WeakSet" | "WeakRef" | "BigInt" | "Window" | "Global" | "Unknown";
/** Type of unsubscribe */
type Unsubscribe = Callback;
/**
* The parameter type of the subscription listening function
* @description subscribe possesses the characteristic scheduling mechanism of Resy itself,
* as well as the ability to handle batch updates.
* effectState is the data state for a batch change,
* while prevState and nextState represent the data states before and after a batch change.
*/
type ListenerParams<S extends PrimitiveState> = {
effectState: Readonly<Partial<S>>;
nextState: Readonly<S>;
prevState: Readonly<S>;
};
/** Type of monitoring callback for subscription */
type ListenerType<S extends PrimitiveState> = (data: ListenerParams<S>) => void;
/** Type of subscribe */
type Subscribe<S extends PrimitiveState> = Readonly<{
/**
* @param listener
* @param stateKeys Array of monitored data attributes
* @return unsubscribe
*/
subscribe(listener: ListenerType<S>, stateKeys?: (keyof S)[]): Unsubscribe;
}>;
declare const __CLASS_CONNECT_STORE_KEY__: unique symbol;
declare const __CLASS_THIS_POINTER_STORES_KEY__: unique symbol;
/**
* Performs some action. This method should not be overridden in subclasses.
* Even if you rewrite it, your rewriting method won't work.
* @method connectStore
* @description This is an important method that is core to the functionality of this class.
*/
type ConnectStoreType = {
connectStore<S extends PrimitiveState>(store: S): S;
};
/** This is the data type returned by the class after connecting to the store */
type ClassStoreType<S extends PrimitiveState> = S & StoreCoreUtils<S> & SetOptions;
/**
* @description The second parameter configuration item of createStore
*/
type StoreOptions = Readonly<{
/**
* @description Whether to reset and restore the data to its initial state
* when all modules used by the current page are unmount.
* In the case of global data such as login information or themes,
* it would be set to false, so that the resulting loginStore or themeStore can take effect globally across the system.
* @default true
*/
unmountRestore?: boolean;
/**
* Configuration for useConciseState hooks (internal, not recommended externally)
* @default undefined
*/
__useConciseStateMode__?: boolean;
}>;
/** Type of key disabled in the initialization parameters */
type InitialStateForbiddenKeys = "setState" | "syncUpdate" | "subscribe" | "restore" | "setOptions" | "useStore" | "useSubscription" | "store";
/** Update the data type of the parameter */
type State<S extends PrimitiveState> = Partial<S> | S | null;
/** Type of setState */
type SetState<S extends PrimitiveState> = Readonly<{
/**
* @param state
* @param callback
*/
setState(state: State<S> | StateFnType<S>, callback?: StateCallback<S>): void;
}>;
/**
* The type of update parameter is function parameter
* @description The presence of prevState is necessary.
* In complex business updating logic and event loops,
* being able to directly obtain the previous synchronized state
* through simple synchronous code is a very smooth and simple method.
*/
type StateFnType<S extends PrimitiveState> = (prevState: Readonly<S>) => State<S>;
/**
* Type of callback functions for setState, syncUpdate, and restore
* @description The existence of the nextState parameter in the callback is also necessary for reasons similar to prevState.
*/
type StateCallback<S extends PrimitiveState> = (nextState: Readonly<S>) => void;
/** Type of syncUpdate */
type SyncUpdate<S extends PrimitiveState> = Readonly<{
/**
* @param state
* @param callback
*/
syncUpdate(state: State<S> | StateFnType<S>, callback?: StateCallback<S>): void;
}>;
/** Type of restore */
type Restore<S extends PrimitiveState> = Readonly<{
/**
* @param callback
* @description The reason for not naming it reset is due to
* the consideration of scenarios where the createStore parameter might be a function.
* In such cases, logically speaking, it's not so much about resetting but rather about restoring.
* As for what state it restores to depends on the result returned by the execution of the initialization function.
* Hence, the choice of the name restore instead of reset.
*/
restore(callback?: StateCallback<S>): void;
}>;
/**
* Type of setOptions
* @description The reason why changing StoreOptions is permissible is due to the needs of business scenarios
* and the desire to keep development channels open and flexible.
* This is because the static execution of createStore is by itself a limitation.
* If there is a need for sudden changes in certain scenarios
* and the static parameter settings cannot be made changeable at that time,
* it would be a constraint. The existence of setOptions can lift this static restriction,
* and setOptions should be considered an aid. However, generally speaking,
* the configuration of StoreOptions itself should meet and satisfy the vast majority of usage scenarios,
* so the occurrences where setOptions is needed are still relatively rare.
*/
type SetOptions = Readonly<{
setOptions(options: {
unmountRestore: boolean;
}): void;
}>;
/** store.useStore() */
type UseStore<S extends PrimitiveState> = Readonly<{
useStore(): S & StoreCoreUtils<S> & SetOptions;
}>;
/** store.UseSubscription() */
type UseSubscription<S extends PrimitiveState> = Readonly<{
useSubscription(listener: ListenerType<S>, stateKeys?: (keyof S)[]): void;
}>;
/** Some of the core tool method types of store */
type StoreCoreUtils<S extends PrimitiveState> = SetState<S> & SyncUpdate<S> & Restore<S> & Subscribe<S>;
/** Tool method type of store */
type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & SetOptions & UseStore<S> & UseSubscription<S>;
/** The type of store returned by createStore */
type Store<S extends PrimitiveState> = S & StoreUtils<S>;
/** Return type of useConciseState */
type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & {
readonly store: S & StoreCoreUtils<S>;
};
/** thisType type used to initialize store when initialState is a function */
type InitialStore<S extends PrimitiveState> = {
[K in keyof S]: K extends InitialStateForbiddenKeys ? never : S[K];
} & StoreCoreUtils<S> & SetOptions;
/** Parameter types disabled for initialization of InitialState */
type PrimateForbiddenType = number | string | null | Symbol | boolean | Set<any> | Map<any, any> | Array<any> | WeakSet<any> | WeakMap<any, any> | WeakRef<any> | RegExp | BigInt | Date | Window;
/** Parameter types with this type pointing to identification */
type StateWithThisType<S extends PrimitiveState> = S extends PrimateForbiddenType ? never : S & {
[K in keyof S]: K extends InitialStateForbiddenKeys ? never : S[K];
} & ThisType<InitialStore<S>>;
/** Type of initialize data */
type InitialState<S extends PrimitiveState> = (() => StateWithThisType<S>) | StateWithThisType<S>;
/**
* createStore
* created by liushanbao
* @description Create a state storage container that can be used globally
* @author liushanbao
* @date 2022-05-05
* @param initialState
* @param options
* @return Store<S>
*/
declare const createStore: <S extends PrimitiveState>(initialState?: InitialState<S> | undefined, options?: StoreOptions) => Store<S>;
/**
* useStore api
* @description useStore(store) === store.useStore()
* @param store
* @return store
*/
declare const useStore: <S extends PrimitiveState>(store: S) => S;
/**
* A concise version of useState
* @example:
* const { count, text, setState } = useConciseState({ count: 0, text: "hello" });
* equivalent to:
* const [count, setCount] = useState(0);
* const [text, setText] = useState("hello");
* 🌟 useConciseState is relatively simple and clear to use compared to useState when dealing with multiple data states.
* 🌟 Furthermore, within useConciseState, the store attribute can be parsed out, and through the store,
* the latest data values of various items can be accessed,
* compensating for the shortfall in useState where the latest values of attribute data cannot be retrieved.
* @param initialState
* @return ConciseStore<S>
*/
declare const useConciseState: <S extends PrimitiveState>(initialState?: InitialState<S> | undefined) => ConciseStore<S>;
declare const useSubscription: <S extends PrimitiveState>(store: S, listener: ListenerType<S>, stateKeys?: (keyof S)[] | undefined) => void;
/**
* @class ComponentWithStore
* @classdesc The public base class can connect to the store
*/
declare class ComponentWithStore<P = {}, S = {}, SS = any> extends Component<P, S, SS> implements ConnectStoreType {
constructor(props: P);
private unmountExecuted;
/**
* Performs unmount processing logic
*/
private unmountProcessing;
private [__CLASS_CONNECT_STORE_KEY__];
private [__CLASS_THIS_POINTER_STORES_KEY__];
connectStore<S extends PrimitiveState>(store: S): S;
}
/**
* @class PureComponentWithStore
* @classdesc The public base class can connect to the store
*/
declare class PureComponentWithStore<P = {}, S = {}, SS = any> extends PureComponent<P, S, SS> implements ConnectStoreType {
constructor(props: P);
private unmountExecuted;
/**
* Performs unmount processing logic
*/
private unmountProcessing;
private [__CLASS_CONNECT_STORE_KEY__];
private [__CLASS_THIS_POINTER_STORES_KEY__];
connectStore<S extends PrimitiveState>(store: S): S;
}
export { AnyFn, Callback, ClassStoreType, ComponentWithStore, ConciseStore, ConnectStoreType, InitialState, InitialStateForbiddenKeys, InitialStore, ListenerParams, ListenerType, MapType, NativeDataType, PrimateForbiddenType, PrimitiveState, PureComponentWithStore, Restore, SetOptions, SetState, State, StateCallback, StateFnType, StateWithThisType, Store, StoreCoreUtils, StoreOptions, StoreUtils, Subscribe, SyncUpdate, Unsubscribe, UseStore, ValueOf, createStore, useConciseState, useStore, useSubscription };
/**
* resy
* An easy-to-use React data state manager
* created by liushanbao <1262300490@qq.com>
* (c) 2020-05-05-2024-3-02
* Released under the MIT License.
*/
import { Component, PureComponent } from 'react';
type Callback = () => void;
type PrimitiveState = Record<number | string, any>;
type AnyFn = (...args: unknown[]) => unknown;
type ValueOf<S extends PrimitiveState> = S[keyof S];
type MapType<S extends PrimitiveState> = Map<keyof S, ValueOf<S>>;
type NativeDataType = "Number" | "String" | "Boolean" | "Undefined" | "Null" | "Symbol" | "Object" | "Function" | "Array" | "Date" | "RegExp" | "Map" | "Set" | "WeakMap" | "WeakSet" | "WeakRef" | "BigInt" | "Window" | "Global" | "Unknown";
/** Type of unsubscribe */
type Unsubscribe = Callback;
/**
* The parameter type of the subscription listening function
* @description subscribe possesses the characteristic scheduling mechanism of Resy itself,
* as well as the ability to handle batch updates.
* effectState is the data state for a batch change,
* while prevState and nextState represent the data states before and after a batch change.
*/
type ListenerParams<S extends PrimitiveState> = {
effectState: Readonly<Partial<S>>;
nextState: Readonly<S>;
prevState: Readonly<S>;
};
/** Type of monitoring callback for subscription */
type ListenerType<S extends PrimitiveState> = (data: ListenerParams<S>) => void;
/** Type of subscribe */
type Subscribe<S extends PrimitiveState> = Readonly<{
/**
* @param listener
* @param stateKeys Array of monitored data attributes
* @return unsubscribe
*/
subscribe(listener: ListenerType<S>, stateKeys?: (keyof S)[]): Unsubscribe;
}>;
declare const __CLASS_CONNECT_STORE_KEY__: unique symbol;
declare const __CLASS_THIS_POINTER_STORES_KEY__: unique symbol;
/**
* Performs some action. This method should not be overridden in subclasses.
* Even if you rewrite it, your rewriting method won't work.
* @method connectStore
* @description This is an important method that is core to the functionality of this class.
*/
type ConnectStoreType = {
connectStore<S extends PrimitiveState>(store: S): S;
};
/** This is the data type returned by the class after connecting to the store */
type ClassStoreType<S extends PrimitiveState> = S & StoreCoreUtils<S> & SetOptions;
/**
* @description The second parameter configuration item of createStore
*/
type StoreOptions = Readonly<{
/**
* @description Whether to reset and restore the data to its initial state
* when all modules used by the current page are unmount.
* In the case of global data such as login information or themes,
* it would be set to false, so that the resulting loginStore or themeStore can take effect globally across the system.
* @default true
*/
unmountRestore?: boolean;
/**
* Configuration for useConciseState hooks (internal, not recommended externally)
* @default undefined
*/
__useConciseStateMode__?: boolean;
}>;
/** Type of key disabled in the initialization parameters */
type InitialStateForbiddenKeys = "setState" | "syncUpdate" | "subscribe" | "restore" | "setOptions" | "useStore" | "useSubscription" | "store";
/** Update the data type of the parameter */
type State<S extends PrimitiveState> = Partial<S> | S | null;
/** Type of setState */
type SetState<S extends PrimitiveState> = Readonly<{
/**
* @param state
* @param callback
*/
setState(state: State<S> | StateFnType<S>, callback?: StateCallback<S>): void;
}>;
/**
* The type of update parameter is function parameter
* @description The presence of prevState is necessary.
* In complex business updating logic and event loops,
* being able to directly obtain the previous synchronized state
* through simple synchronous code is a very smooth and simple method.
*/
type StateFnType<S extends PrimitiveState> = (prevState: Readonly<S>) => State<S>;
/**
* Type of callback functions for setState, syncUpdate, and restore
* @description The existence of the nextState parameter in the callback is also necessary for reasons similar to prevState.
*/
type StateCallback<S extends PrimitiveState> = (nextState: Readonly<S>) => void;
/** Type of syncUpdate */
type SyncUpdate<S extends PrimitiveState> = Readonly<{
/**
* @param state
* @param callback
*/
syncUpdate(state: State<S> | StateFnType<S>, callback?: StateCallback<S>): void;
}>;
/** Type of restore */
type Restore<S extends PrimitiveState> = Readonly<{
/**
* @param callback
* @description The reason for not naming it reset is due to
* the consideration of scenarios where the createStore parameter might be a function.
* In such cases, logically speaking, it's not so much about resetting but rather about restoring.
* As for what state it restores to depends on the result returned by the execution of the initialization function.
* Hence, the choice of the name restore instead of reset.
*/
restore(callback?: StateCallback<S>): void;
}>;
/**
* Type of setOptions
* @description The reason why changing StoreOptions is permissible is due to the needs of business scenarios
* and the desire to keep development channels open and flexible.
* This is because the static execution of createStore is by itself a limitation.
* If there is a need for sudden changes in certain scenarios
* and the static parameter settings cannot be made changeable at that time,
* it would be a constraint. The existence of setOptions can lift this static restriction,
* and setOptions should be considered an aid. However, generally speaking,
* the configuration of StoreOptions itself should meet and satisfy the vast majority of usage scenarios,
* so the occurrences where setOptions is needed are still relatively rare.
*/
type SetOptions = Readonly<{
setOptions(options: {
unmountRestore: boolean;
}): void;
}>;
/** store.useStore() */
type UseStore<S extends PrimitiveState> = Readonly<{
useStore(): S & StoreCoreUtils<S> & SetOptions;
}>;
/** store.UseSubscription() */
type UseSubscription<S extends PrimitiveState> = Readonly<{
useSubscription(listener: ListenerType<S>, stateKeys?: (keyof S)[]): void;
}>;
/** Some of the core tool method types of store */
type StoreCoreUtils<S extends PrimitiveState> = SetState<S> & SyncUpdate<S> & Restore<S> & Subscribe<S>;
/** Tool method type of store */
type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & SetOptions & UseStore<S> & UseSubscription<S>;
/** The type of store returned by createStore */
type Store<S extends PrimitiveState> = S & StoreUtils<S>;
/** Return type of useConciseState */
type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & {
readonly store: S & StoreCoreUtils<S>;
};
/** thisType type used to initialize store when initialState is a function */
type InitialStore<S extends PrimitiveState> = {
[K in keyof S]: K extends InitialStateForbiddenKeys ? never : S[K];
} & StoreCoreUtils<S> & SetOptions;
/** Parameter types disabled for initialization of InitialState */
type PrimateForbiddenType = number | string | null | Symbol | boolean | Set<any> | Map<any, any> | Array<any> | WeakSet<any> | WeakMap<any, any> | WeakRef<any> | RegExp | BigInt | Date | Window;
/** Parameter types with this type pointing to identification */
type StateWithThisType<S extends PrimitiveState> = S extends PrimateForbiddenType ? never : S & {
[K in keyof S]: K extends InitialStateForbiddenKeys ? never : S[K];
} & ThisType<InitialStore<S>>;
/** Type of initialize data */
type InitialState<S extends PrimitiveState> = (() => StateWithThisType<S>) | StateWithThisType<S>;
/**
* createStore
* created by liushanbao
* @description Create a state storage container that can be used globally
* @author liushanbao
* @date 2022-05-05
* @param initialState
* @param options
* @return Store<S>
*/
declare const createStore: <S extends PrimitiveState>(initialState?: InitialState<S> | undefined, options?: StoreOptions) => Store<S>;
/**
* useStore api
* @description useStore(store) === store.useStore()
* @param store
* @return store
*/
declare const useStore: <S extends PrimitiveState>(store: S) => S;
/**
* A concise version of useState
* @example:
* const { count, text, setState } = useConciseState({ count: 0, text: "hello" });
* equivalent to:
* const [count, setCount] = useState(0);
* const [text, setText] = useState("hello");
* 🌟 useConciseState is relatively simple and clear to use compared to useState when dealing with multiple data states.
* 🌟 Furthermore, within useConciseState, the store attribute can be parsed out, and through the store,
* the latest data values of various items can be accessed,
* compensating for the shortfall in useState where the latest values of attribute data cannot be retrieved.
* @param initialState
* @return ConciseStore<S>
*/
declare const useConciseState: <S extends PrimitiveState>(initialState?: InitialState<S> | undefined) => ConciseStore<S>;
declare const useSubscription: <S extends PrimitiveState>(store: S, listener: ListenerType<S>, stateKeys?: (keyof S)[] | undefined) => void;
/**
* @class ComponentWithStore
* @classdesc The public base class can connect to the store
*/
declare class ComponentWithStore<P = {}, S = {}, SS = any> extends Component<P, S, SS> implements ConnectStoreType {
constructor(props: P);
private unmountExecuted;
/**
* Performs unmount processing logic
*/
private unmountProcessing;
private [__CLASS_CONNECT_STORE_KEY__];
private [__CLASS_THIS_POINTER_STORES_KEY__];
connectStore<S extends PrimitiveState>(store: S): S;
}
/**
* @class PureComponentWithStore
* @classdesc The public base class can connect to the store
*/
declare class PureComponentWithStore<P = {}, S = {}, SS = any> extends PureComponent<P, S, SS> implements ConnectStoreType {
constructor(props: P);
private unmountExecuted;
/**
* Performs unmount processing logic
*/
private unmountProcessing;
private [__CLASS_CONNECT_STORE_KEY__];
private [__CLASS_THIS_POINTER_STORES_KEY__];
connectStore<S extends PrimitiveState>(store: S): S;
}
export { AnyFn, Callback, ClassStoreType, ComponentWithStore, ConciseStore, ConnectStoreType, InitialState, InitialStateForbiddenKeys, InitialStore, ListenerParams, ListenerType, MapType, NativeDataType, PrimateForbiddenType, PrimitiveState, PureComponentWithStore, Restore, SetOptions, SetState, State, StateCallback, StateFnType, StateWithThisType, Store, StoreCoreUtils, StoreOptions, StoreUtils, Subscribe, SyncUpdate, Unsubscribe, UseStore, ValueOf, createStore, useConciseState, useStore, useSubscription };
/**
* resy
* An easy-to-use React data state manager
* created by liushanbao <1262300490@qq.com>
* (c) 2020-05-05-2024-3-02
* Released under the MIT License.
*/
import { Component, PureComponent } from 'react';
type Callback = () => void;
type PrimitiveState = Record<number | string, any>;
type AnyFn = (...args: unknown[]) => unknown;
type ValueOf<S extends PrimitiveState> = S[keyof S];
type MapType<S extends PrimitiveState> = Map<keyof S, ValueOf<S>>;
type NativeDataType = "Number" | "String" | "Boolean" | "Undefined" | "Null" | "Symbol" | "Object" | "Function" | "Array" | "Date" | "RegExp" | "Map" | "Set" | "WeakMap" | "WeakSet" | "WeakRef" | "BigInt" | "Window" | "Global" | "Unknown";
/** Type of unsubscribe */
type Unsubscribe = Callback;
/**
* The parameter type of the subscription listening function
* @description subscribe possesses the characteristic scheduling mechanism of Resy itself,
* as well as the ability to handle batch updates.
* effectState is the data state for a batch change,
* while prevState and nextState represent the data states before and after a batch change.
*/
type ListenerParams<S extends PrimitiveState> = {
effectState: Readonly<Partial<S>>;
nextState: Readonly<S>;
prevState: Readonly<S>;
};
/** Type of monitoring callback for subscription */
type ListenerType<S extends PrimitiveState> = (data: ListenerParams<S>) => void;
/** Type of subscribe */
type Subscribe<S extends PrimitiveState> = Readonly<{
/**
* @param listener
* @param stateKeys Array of monitored data attributes
* @return unsubscribe
*/
subscribe(listener: ListenerType<S>, stateKeys?: (keyof S)[]): Unsubscribe;
}>;
declare const __CLASS_CONNECT_STORE_KEY__: unique symbol;
declare const __CLASS_THIS_POINTER_STORES_KEY__: unique symbol;
/**
* Performs some action. This method should not be overridden in subclasses.
* Even if you rewrite it, your rewriting method won't work.
* @method connectStore
* @description This is an important method that is core to the functionality of this class.
*/
type ConnectStoreType = {
connectStore<S extends PrimitiveState>(store: S): S;
};
/** This is the data type returned by the class after connecting to the store */
type ClassStoreType<S extends PrimitiveState> = S & StoreCoreUtils<S> & SetOptions;
/**
* @description The second parameter configuration item of createStore
*/
type StoreOptions = Readonly<{
/**
* @description Whether to reset and restore the data to its initial state
* when all modules used by the current page are unmount.
* In the case of global data such as login information or themes,
* it would be set to false, so that the resulting loginStore or themeStore can take effect globally across the system.
* @default true
*/
unmountRestore?: boolean;
/**
* Configuration for useConciseState hooks (internal, not recommended externally)
* @default undefined
*/
__useConciseStateMode__?: boolean;
}>;
/** Type of key disabled in the initialization parameters */
type InitialStateForbiddenKeys = "setState" | "syncUpdate" | "subscribe" | "restore" | "setOptions" | "useStore" | "useSubscription" | "store";
/** Update the data type of the parameter */
type State<S extends PrimitiveState> = Partial<S> | S | null;
/** Type of setState */
type SetState<S extends PrimitiveState> = Readonly<{
/**
* @param state
* @param callback
*/
setState(state: State<S> | StateFnType<S>, callback?: StateCallback<S>): void;
}>;
/**
* The type of update parameter is function parameter
* @description The presence of prevState is necessary.
* In complex business updating logic and event loops,
* being able to directly obtain the previous synchronized state
* through simple synchronous code is a very smooth and simple method.
*/
type StateFnType<S extends PrimitiveState> = (prevState: Readonly<S>) => State<S>;
/**
* Type of callback functions for setState, syncUpdate, and restore
* @description The existence of the nextState parameter in the callback is also necessary for reasons similar to prevState.
*/
type StateCallback<S extends PrimitiveState> = (nextState: Readonly<S>) => void;
/** Type of syncUpdate */
type SyncUpdate<S extends PrimitiveState> = Readonly<{
/**
* @param state
* @param callback
*/
syncUpdate(state: State<S> | StateFnType<S>, callback?: StateCallback<S>): void;
}>;
/** Type of restore */
type Restore<S extends PrimitiveState> = Readonly<{
/**
* @param callback
* @description The reason for not naming it reset is due to
* the consideration of scenarios where the createStore parameter might be a function.
* In such cases, logically speaking, it's not so much about resetting but rather about restoring.
* As for what state it restores to depends on the result returned by the execution of the initialization function.
* Hence, the choice of the name restore instead of reset.
*/
restore(callback?: StateCallback<S>): void;
}>;
/**
* Type of setOptions
* @description The reason why changing StoreOptions is permissible is due to the needs of business scenarios
* and the desire to keep development channels open and flexible.
* This is because the static execution of createStore is by itself a limitation.
* If there is a need for sudden changes in certain scenarios
* and the static parameter settings cannot be made changeable at that time,
* it would be a constraint. The existence of setOptions can lift this static restriction,
* and setOptions should be considered an aid. However, generally speaking,
* the configuration of StoreOptions itself should meet and satisfy the vast majority of usage scenarios,
* so the occurrences where setOptions is needed are still relatively rare.
*/
type SetOptions = Readonly<{
setOptions(options: {
unmountRestore: boolean;
}): void;
}>;
/** store.useStore() */
type UseStore<S extends PrimitiveState> = Readonly<{
useStore(): S & StoreCoreUtils<S> & SetOptions;
}>;
/** store.UseSubscription() */
type UseSubscription<S extends PrimitiveState> = Readonly<{
useSubscription(listener: ListenerType<S>, stateKeys?: (keyof S)[]): void;
}>;
/** Some of the core tool method types of store */
type StoreCoreUtils<S extends PrimitiveState> = SetState<S> & SyncUpdate<S> & Restore<S> & Subscribe<S>;
/** Tool method type of store */
type StoreUtils<S extends PrimitiveState> = StoreCoreUtils<S> & SetOptions & UseStore<S> & UseSubscription<S>;
/** The type of store returned by createStore */
type Store<S extends PrimitiveState> = S & StoreUtils<S>;
/** Return type of useConciseState */
type ConciseStore<S extends PrimitiveState> = S & StoreCoreUtils<S> & {
readonly store: S & StoreCoreUtils<S>;
};
/** thisType type used to initialize store when initialState is a function */
type InitialStore<S extends PrimitiveState> = {
[K in keyof S]: K extends InitialStateForbiddenKeys ? never : S[K];
} & StoreCoreUtils<S> & SetOptions;
/** Parameter types disabled for initialization of InitialState */
type PrimateForbiddenType = number | string | null | Symbol | boolean | Set<any> | Map<any, any> | Array<any> | WeakSet<any> | WeakMap<any, any> | WeakRef<any> | RegExp | BigInt | Date | Window;
/** Parameter types with this type pointing to identification */
type StateWithThisType<S extends PrimitiveState> = S extends PrimateForbiddenType ? never : S & {
[K in keyof S]: K extends InitialStateForbiddenKeys ? never : S[K];
} & ThisType<InitialStore<S>>;
/** Type of initialize data */
type InitialState<S extends PrimitiveState> = (() => StateWithThisType<S>) | StateWithThisType<S>;
/**
* createStore
* created by liushanbao
* @description Create a state storage container that can be used globally
* @author liushanbao
* @date 2022-05-05
* @param initialState
* @param options
* @return Store<S>
*/
declare const createStore: <S extends PrimitiveState>(initialState?: InitialState<S> | undefined, options?: StoreOptions) => Store<S>;
/**
* useStore api
* @description useStore(store) === store.useStore()
* @param store
* @return store
*/
declare const useStore: <S extends PrimitiveState>(store: S) => S;
/**
* A concise version of useState
* @example:
* const { count, text, setState } = useConciseState({ count: 0, text: "hello" });
* equivalent to:
* const [count, setCount] = useState(0);
* const [text, setText] = useState("hello");
* 🌟 useConciseState is relatively simple and clear to use compared to useState when dealing with multiple data states.
* 🌟 Furthermore, within useConciseState, the store attribute can be parsed out, and through the store,
* the latest data values of various items can be accessed,
* compensating for the shortfall in useState where the latest values of attribute data cannot be retrieved.
* @param initialState
* @return ConciseStore<S>
*/
declare const useConciseState: <S extends PrimitiveState>(initialState?: InitialState<S> | undefined) => ConciseStore<S>;
declare const useSubscription: <S extends PrimitiveState>(store: S, listener: ListenerType<S>, stateKeys?: (keyof S)[] | undefined) => void;
/**
* @class ComponentWithStore
* @classdesc The public base class can connect to the store
*/
declare class ComponentWithStore<P = {}, S = {}, SS = any> extends Component<P, S, SS> implements ConnectStoreType {
constructor(props: P);
private unmountExecuted;
/**
* Performs unmount processing logic
*/
private unmountProcessing;
private [__CLASS_CONNECT_STORE_KEY__];
private [__CLASS_THIS_POINTER_STORES_KEY__];
connectStore<S extends PrimitiveState>(store: S): S;
}
/**
* @class PureComponentWithStore
* @classdesc The public base class can connect to the store
*/
declare class PureComponentWithStore<P = {}, S = {}, SS = any> extends PureComponent<P, S, SS> implements ConnectStoreType {
constructor(props: P);
private unmountExecuted;
/**
* Performs unmount processing logic
*/
private unmountProcessing;
private [__CLASS_CONNECT_STORE_KEY__];
private [__CLASS_THIS_POINTER_STORES_KEY__];
connectStore<S extends PrimitiveState>(store: S): S;
}
export { AnyFn, Callback, ClassStoreType, ComponentWithStore, ConciseStore, ConnectStoreType, InitialState, InitialStateForbiddenKeys, InitialStore, ListenerParams, ListenerType, MapType, NativeDataType, PrimateForbiddenType, PrimitiveState, PureComponentWithStore, Restore, SetOptions, SetState, State, StateCallback, StateFnType, StateWithThisType, Store, StoreCoreUtils, StoreOptions, StoreUtils, Subscribe, SyncUpdate, Unsubscribe, UseStore, ValueOf, createStore, useConciseState, useStore, useSubscription };