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
31 lines (30 loc) • 1.96 kB
TypeScript
import type { ActionCollectionConfig, GlobalStoreCallbacks, StateChanges, StoreTools } from "react-hooks-global-states/types";
import type { AsyncStorageConfig, BaseMetadata, StateMeta } from "./types";
import { GlobalStoreAbstract } from "react-hooks-global-states/GlobalStoreAbstract";
export declare class GlobalStore<State, Metadata extends BaseMetadata | unknown, ActionsConfig extends ActionCollectionConfig<State, StateMeta<Metadata>> | undefined | unknown> extends GlobalStoreAbstract<State, StateMeta<Metadata>, ActionsConfig> {
protected asyncStorage: AsyncStorageConfig | null;
constructor(state: State);
constructor(state: State, args: {
metadata?: Metadata;
callbacks?: GlobalStoreCallbacks<State, Metadata>;
actions?: ActionsConfig;
name?: string;
asyncStorage?: AsyncStorageConfig;
});
protected getMetadata: () => StateMeta<Metadata>;
static isAsyncStorageAvailable: (config: AsyncStorageConfig | null) => config is AsyncStorageConfig;
protected _onInitialize: ({ setState, getState, setMetadata, }: StoreTools<State, Metadata>) => Promise<void>;
protected _onChange: ({ getState }: StoreTools<State, Metadata> & StateChanges<State>) => void;
/**
* We set it to null so the instances of the GlobalStoreAbstract can override it.
*/
protected onInitialize: (args: StoreTools<State, StateMeta<Metadata>>) => void;
protected onChange: (args: StoreTools<State, StateMeta<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, StateMeta<Metadata>>) => void;
protected onStateChanged: (args: StoreTools<State, StateMeta<Metadata>> & StateChanges<State>) => void;
}
export default GlobalStore;