import type { ComponentType, FC } from 'react'; import type { RemainingArgs, StateDispatcher } from 'piral-core'; declare module 'piral-core/lib/types/custom' { interface PiletCustomApi extends PiletContainersApi {} interface PiralCustomState { /** * The relevant state for the registered containers. */ containers: Record; } interface PiralCustomActions { /** * Creates a new local state. * @param id The id of the state. * @param state The initial state to use. */ createState(id: string, state: TState): void; /** * Destroys an existing local state. * @param id The id of the state. */ destroyState(id: string): void; /** * Replaces the local state with the provided state. * @param id The id of the local state. * @param state The new state to use. */ replaceState(id: string, reducer: StateDispatcher): void; } } export interface PiletContainersApi { /** * Creates a state container for persisting some global state. * @param options The options for creating the state container. */ createState>( options: StateContainerOptions, ): StateContainer>; } export interface StateContainerReducer { (dispatch: StateDispatcher): void; } export type StateContainerReducers = { [name: string]: (dispatch: StateContainerReducer, ...args: any) => void; }; export interface StateContainerOptions> { /** * The initial state value. */ state: TState; /** * The available actions. */ actions: TActions; } export interface StateConnectorProps { /** * The currently available state. */ state: TState; /** * The actions for changing the state. */ actions: TAction; } export type StateContainerActions = { [P in keyof TActions]: (...args: RemainingArgs) => void }; export interface StateContainer { /** * State container connector function for wrapping a component. * @param component The component to connect by providing a state and an action prop. */ (component: ComponentType>): FC; }