UNPKG

react-model

Version:

The State management library for React

73 lines (72 loc) 4.38 kB
/// <reference path="../src/index.d.ts" /> import * as React from 'react'; import { PureComponent } from 'react'; import Global from './global'; import { Consumer, getInitialState } from './helper'; import { actionMiddlewares, middlewares } from './middlewares'; declare function useModel<S>(state: S | (() => S)): [S, (state: Partial<S> | ((state: S) => S | void)) => void]; declare function createStore<S>(useHook: CustomModelHook<S>): LaneAPI<S>; declare function createStore<S>(name: string, useHook: CustomModelHook<S>): LaneAPI<S>; declare function Model<E, Ctx extends {}, MT extends ModelType<any, any, {}>>(models: MT, initialState?: E): API<MT>; declare function Model<M extends Models, E>(models: M, initialState?: Global['State']): APIs<M>; declare const getState: (modelName: keyof typeof Global.State) => any; declare class Provider extends PureComponent<{}, Global['State']> { state: { [modelName: string]: any; }; render(): JSX.Element; } declare const connect: (modelName: string, mapState?: Function | undefined, mapActions?: Function | undefined) => (Component: typeof React.PureComponent | typeof React.Component) => { new (props: any): { render(): JSX.Element; context: any; setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<any>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; forceUpdate(callback?: (() => void) | undefined): void; readonly props: Readonly<any> & Readonly<{ children?: React.ReactNode; }>; state: Readonly<{}>; refs: { [key: string]: React.ReactInstance; }; componentDidMount?(): void; shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): boolean; componentWillUnmount?(): void; componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>): any; componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>, snapshot?: any): void; componentWillMount?(): void; UNSAFE_componentWillMount?(): void; componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void; UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void; componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void; UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void; }; new (props: any, context: any): { render(): JSX.Element; context: any; setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<any>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void; forceUpdate(callback?: (() => void) | undefined): void; readonly props: Readonly<any> & Readonly<{ children?: React.ReactNode; }>; state: Readonly<{}>; refs: { [key: string]: React.ReactInstance; }; componentDidMount?(): void; shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): boolean; componentWillUnmount?(): void; componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void; getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>): any; componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>, snapshot?: any): void; componentWillMount?(): void; UNSAFE_componentWillMount?(): void; componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void; UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void; componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void; UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void; }; contextType?: React.Context<any> | undefined; }; export { actionMiddlewares, createStore, useModel, Model, middlewares, Provider, Consumer, connect, getState, getInitialState };