mobx-state-tree
Version:
Opinionated, transactional, MobX powered state container
36 lines (35 loc) • 1.29 kB
TypeScript
import { ISimpleType, Type } from "../type";
import { TypeFlags } from "../type-flags";
import { IContext, IValidationResult } from "../type-checker";
import { Node } from "../../core";
export declare class Frozen<T> extends Type<T, T> {
flags: TypeFlags;
constructor();
describe(): string;
instantiate(parent: Node | null, subpath: string, environment: any, value: any): Node;
isValidSnapshot(value: any, context: IContext): IValidationResult;
}
/**
* Frozen can be used to story any value that is serializable in itself (that is valid JSON).
* Frozen values need to be immutable or treated as if immutable.
* Values stored in frozen will snapshotted as-is by MST, and internal changes will not be tracked.
*
* This is useful to store complex, but immutable values like vectors etc. It can form a powerful bridge to parts of your application that should be immutable, or that assume data to be immutable.
*
* @example
* const GameCharacter = types.model({
* name: string,
* location: types.frozen
* })
*
* const hero = new GameCharacter({
* name: "Mario",
* location: { x: 7, y: 4 }
* })
*
* hero.location = { x: 10, y: 2 } // OK
* hero.location.x = 7 // Not ok!
*
* @alias types.frozen
*/
export declare const frozen: ISimpleType<any>;