react-native-global-state-hooks
Version:
This is a package to easily handling global-state across your react-native-components No-redux... The library now includes @react-native-async-storage/async-storage to persist your state across sessions... if you want to keep using the old version without
34 lines (33 loc) • 2.36 kB
TypeScript
import type { ActionCollectionConfig, GlobalStoreCallbacks, StateChanges, StoreTools } from "react-hooks-global-states/types";
import type { ActionCollectionResult, AsyncStorageConfig, AsyncMetadata, BaseMetadata, AnyFunction } from "./types";
import { GlobalStoreAbstract } from "react-hooks-global-states/GlobalStoreAbstract";
/**
* React Native Global Store with Async Storage support
*/
export declare class GlobalStore<State, Metadata extends AsyncMetadata, ActionsConfig extends ActionCollectionConfig<State, Metadata> | undefined | unknown, PublicStateMutator = keyof ActionsConfig extends never | undefined ? React.Dispatch<React.SetStateAction<State>> : ActionCollectionResult<State, Metadata, NonNullable<ActionsConfig>>> extends GlobalStoreAbstract<State, BaseMetadata<Metadata>, ActionsConfig> {
asyncStorage: AsyncStorageConfig | null;
constructor(state: State);
constructor(state: State, args: {
metadata?: Metadata;
callbacks?: GlobalStoreCallbacks<State, PublicStateMutator extends AnyFunction ? null : PublicStateMutator, Metadata>;
actions?: ActionsConfig;
name?: string;
asyncStorage?: AsyncStorageConfig;
});
getMetadata: () => BaseMetadata<Metadata>;
static isAsyncStorageAvailable: (config: AsyncStorageConfig | null) => config is AsyncStorageConfig;
protected _onInitialize: ({ setState, getState, setMetadata, }: StoreTools<State, PublicStateMutator, Metadata>) => Promise<void>;
protected _onChange: ({ getState, }: StoreTools<State, PublicStateMutator, Metadata> & StateChanges<State>) => void;
/**
* We set it to null so the instances of the GlobalStoreAbstract can override it.
*/
protected onInitialize: (args: StoreTools<State, PublicStateMutator, Metadata>) => void;
protected onChange: (args: StoreTools<State, PublicStateMutator, Metadata> & StateChanges<State>) => void;
/**
* Instead of calling onInitialize and onChange directly, we call the _onInitialize and _onChange
* This allows the concat the logic of the GlobalStore with the logic of the extension class.
*/
protected onInit: (parameters: StoreTools<State, PublicStateMutator, Metadata>) => void;
protected onStateChanged: (args: StoreTools<State, PublicStateMutator, Metadata> & StateChanges<State>) => void;
}
export default GlobalStore;