UNPKG

mobx-keystone-mindreframer

Version:

A MobX powered state management solution based on data trees with first class support for Typescript, snapshots, patches and much more

54 lines (53 loc) 1.91 kB
import type { AnyStandardType, TypeToData } from "../typeChecking/schemas"; import { FnModelActions, FnModelActionsDef } from "./actions"; declare const dataTypeSymbol: unique symbol; /** * Basic functional model methods. */ export interface FnModelBase<Data extends object, Extra> { [dataTypeSymbol]: Data; /** * Turns data into a tree node and additionally performs a type check * if model auto type checking is enabled in the global config * and a type was specified. * * @param data Model data. */ create(data: Data): Data; /** * Returns the type the model is based on, or `null` if none. */ type: AnyStandardType | null; /** * Adds actions to the model. * * @param actions Actions to add. */ actions<A extends FnModelActionsDef>(actions: ThisType<Data> & A): FnModel<Data, Extra & FnModelActions<Data, A>>; } /** * Functional model. */ export declare type FnModel<Data extends object, Extra> = Extra & FnModelBase<Data, Extra>; /** * Gets the data type of a functional model. */ export declare type FnModelData<FN extends FnModelBase<any, any>> = FN[typeof dataTypeSymbol]; /** * Creates a functional model, which can be later extended with views, actions, etc. * * @typeparam DataType Data type. * @param dataType Data type, which must be of an object kind. * @param namespace Namespace for its actions. * @returns */ export declare function fnModel<DataType extends AnyStandardType>(dataType: DataType, namespace: string): FnModel<TypeToData<DataType>, {}>; /** * Creates a functional model, which can be later extended with views, actions, etc. * * @typeparam Data Data type. * @param namespace Namespace for its actions. * @returns */ export declare function fnModel<Data extends object>(namespace: string): FnModel<Data, {}>; export {};