UNPKG

mobx-keystone

Version:

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

51 lines (50 loc) 1.55 kB
/** * Should freeze and plain json checks be done when creating the frozen object? */ export declare enum FrozenCheckMode { /** Only when in dev mode */ DevModeOnly = "devModeOnly", /** Always */ On = "on", /** Never */ Off = "off" } /** * @ignore */ export declare const frozenKey = "$frozen"; /** * A class that contains frozen data. * Use `frozen` to create an instance of this class. * * @template T Data type. */ export declare class Frozen<T> { /** * Frozen data, deeply immutable. */ readonly data: T; /** * Creates an instance of Frozen. * Do not use directly, use `frozen` instead. * * @param dataToFreeze * @param checkMode */ constructor(dataToFreeze: T, checkMode?: FrozenCheckMode); } /** * Marks some data as frozen. Frozen data becomes immutable (at least in dev mode), and is not enhanced * with capabilities such as getting the parent of the objects (except for the root object), it is not * made deeply observable (though the root object is observable by reference), etc. * On the other hand, this means it will be much faster to create/access. Use this for big data pieces * that are unlikely to change unless all of them change (for example lists of points for a polygon, etc). * * Note that data passed to frozen must be serializable to JSON, this is: * - primitive, plain object, or array * - without cycles * * @param data * @param checkMode */ export declare function frozen<T>(data: T, checkMode?: FrozenCheckMode): Frozen<T>;