mobx-keystone
Version:
A MobX powered state management solution based on data trees with first class support for TypeScript, snapshots, patches and much more
71 lines (70 loc) • 2.29 kB
TypeScript
import { Path } from '../parent/pathTypes';
/**
* A class with the implementationm of draft.
* Use `draft` to create an instance of this class.
*
* @template T Data type.
*/
export declare class Draft<T extends object> {
/**
* Draft data object.
*/
readonly data: T;
/**
* Commits current draft changes to the original object.
*/
commit(): void;
/**
* Partially commits current draft changes to the original object.
* If the path cannot be resolved in either the draft or the original object it will throw.
* Note that model IDs are checked to be the same when resolving the paths.
*
* @param path Path to commit.
*/
commitByPath(path: Path): void;
/**
* Resets the draft to be an exact copy of the current state of the original object.
*/
reset(): void;
/**
* Partially resets current draft changes to be the same as the original object.
* If the path cannot be resolved in either the draft or the original object it will throw.
* Note that model IDs are checked to be the same when resolving the paths.
*
* @param path Path to reset.
*/
resetByPath(path: Path): void;
/**
* Returns `true` if the draft has changed compared to the original object, `false` otherwise.
*/
get isDirty(): boolean;
/**
* Returns `true` if the value at the given path of the draft has changed compared to the original object.
* If the path cannot be resolved in the draft it will throw.
* If the path cannot be resolved in the original object it will return `true`.
* Note that model IDs are checked to be the same when resolving the paths.
*
* @param path Path to check.
*/
isDirtyByPath(path: Path): boolean;
/**
* Original data object.
*/
readonly originalData: T;
private get originalSnapshot();
/**
* Creates an instance of Draft.
* Do not use directly, use `draft` instead.
*
* @param original
*/
constructor(original: T);
}
/**
* Creates a draft copy of a tree node and all its children.
*
* @template T Data type.
* @param original Original node.
* @returns The draft object.
*/
export declare function draft<T extends object>(original: T): Draft<T>;