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
65 lines (64 loc) • 1.72 kB
TypeScript
/**
* A context.
*/
export interface Context<T> {
/**
* Gets the context default value.
*
* @returns
*/
getDefault(): T;
/**
* Sets the context default value.
* @param value
*/
setDefault(value: T): void;
/**
* Sets the context default value resolver.
* @param valueFn
*/
setDefaultComputed(valueFn: () => T): void;
/**
* Gets the context value for a given node.
* @param node
*/
get(node: object): T;
/**
* Gets node that will provide the context value, or `undefined`
* if it comes from the default.
* @param node
*/
getProviderNode(node: object): object | undefined;
/**
* Sets the context value for a given node, effectively making it a provider.
* @param node
* @param value
*/
set(node: object, value: T): void;
/**
* Sets the context value resolver for a given node, effectively making it a provider.
* @param node
* @param valueFn
*/
setComputed(node: object, valueFn: () => T): void;
/**
* Unsets the context value for a given node, therefore it won't be a provider anymore.
* @param node
*/
unset(node: object): void;
}
/**
* Creates a new context with no default value, thus making its default value undefined.
*
* @typeparam T Context value type.
* @returns
*/
export declare function createContext<T>(): Context<T | undefined>;
/**
* Creates a new context with a default value.
*
* @typeparam T Context value type.
* @param defaultValue
* @returns
*/
export declare function createContext<T>(defaultValue: T): Context<T>;