UNPKG

3.37 kBTypeScriptView Raw
1export declare class Node {
2 readonly nodeId: number;
3 readonly type: IType<any, any>;
4 readonly storedValue: any;
5 protected _parent: Node | null;
6 subpath: string;
7 identifierCache: IdentifierCache | undefined;
8 isProtectionEnabled: boolean;
9 identifierAttribute: string | undefined;
10 _environment: any;
11 _isRunningAction: boolean;
12 private _autoUnbox;
13 private _isAlive;
14 private _isDetaching;
15 readonly middlewares: IMiddlewareHandler[];
16 private readonly snapshotSubscribers;
17 private readonly patchSubscribers;
18 private readonly disposers;
19 applyPatches: (patches: IJsonPatch[]) => void;
20 applySnapshot: (snapshot: any) => void;
21 constructor(type: IType<any, any>, parent: Node | null, subpath: string, environment: any, initialValue: any, createNewInstance?: (initialValue: any) => any, finalizeNewInstance?: (node: Node, initialValue: any) => void);
22 readonly identifier: string | null;
23 readonly path: string;
24 readonly isRoot: boolean;
25 readonly parent: Node | null;
26 readonly root: Node;
27 getRelativePathTo(target: Node): string;
28 resolve(pathParts: string): Node;
29 resolve(pathParts: string, failIfResolveFails: boolean): Node | undefined;
30 resolvePath(pathParts: string[]): Node;
31 resolvePath(pathParts: string[], failIfResolveFails: boolean): Node | undefined;
32 readonly value: any;
33 readonly isAlive: boolean;
34 die(): void;
35 aboutToDie(): void;
36 finalizeDeath(): void;
37 assertAlive(): void;
38 readonly snapshot: any;
39 onSnapshot(onChange: (snapshot: any) => void): IDisposer;
40 emitSnapshot(snapshot: any): void;
41 applyPatchLocally(subpath: string, patch: IJsonPatch): void;
42 onPatch(handler: (patch: IJsonPatch, reversePatch: IJsonPatch) => void): IDisposer;
43 emitPatch(basePatch: IReversibleJsonPatch, source: Node): void;
44 setParent(newParent: Node | null, subpath?: string | null): void;
45 addDisposer(disposer: () => void): void;
46 isRunningAction(): boolean;
47 addMiddleWare(handler: IMiddlewareHandler): IDisposer;
48 getChildNode(subpath: string): Node;
49 getChildren(): Node[];
50 getChildType(key: string): IType<any, any>;
51 readonly isProtected: boolean;
52 assertWritable(): void;
53 removeChild(subpath: string): void;
54 detach(): void;
55 unbox(childNode: Node): any;
56 fireHook(name: string): void;
57 toString(): string;
58}
59export declare type IStateTreeNode = {
60 readonly $treenode?: any;
61};
62/**
63 * Returns true if the given value is a node in a state tree.
64 * More precisely, that is, if the value is an instance of a
65 * `types.model`, `types.array` or `types.map`.
66 *
67 * @export
68 * @param {*} value
69 * @returns {value is IStateTreeNode}
70 */
71export declare function isStateTreeNode(value: any): value is IStateTreeNode;
72export declare function getStateTreeNode(value: IStateTreeNode): Node;
73export declare function createNode<S, T>(type: IType<S, T>, parent: Node | null, subpath: string, environment: any, initialValue: any, createNewInstance?: (initialValue: any) => T, finalizeNewInstance?: (node: Node, initialValue: any) => void): Node;
74import { IType } from "../types/type";
75import { IReversibleJsonPatch, IJsonPatch } from "./json-patch";
76import { IMiddlewareHandler } from "./action";
77import { IDisposer } from "../utils";
78import { IdentifierCache } from "./identifier-cache";