import { IComputedValue, IComputedValueOptions } from "mobx"; import { AttributeDefinition } from "../kinds/definitions"; import { InheritedAttributeEvaluator } from "../kinds/inherited"; import { SyntheticAttributeEvaluator, CommonSyntheticOptions } from "../kinds/synthetic"; /** * THE TRICK * * So I think I may have finally cracked the code on how to use mobx observable * values without really having to change much in the tree walking. The trick * seems to be that we need to wrap everything in lazily computed * `IComputedValue`s. So instead of our attributes being functions that return * `R`, they should return `IComputeValue`. * * This file contains some simple function that transoform attribute evaluation * functions into ones that provide mobx compatible `IComputedValue` values. * * NB - Regarding caching, if you do not plan to make any structural changes to * the tree, you can probably enable "weakmap" caching. But if there are going * to be structural changes, you'll wind up "memoizing" information about the * structure that will lead to errors when evaluating (because the traversal * will be based on stale information). * * Along these lines, the issue with "weakmap" caching is that the evaluation * code can't detect when the children have changed and that information gets * backed into the "args". If that doesn't get recomputed, then calls to * computedValue.get() lead to traversal over stale elements of the tree. If, * however, children were also computed values (automatically recalculated when * observables changed) or otherwise invalidated on structural changes, then we * could avoid stale data getting memoized. */ export declare const mobx: { synthetic(description: string, f: SyntheticAttributeEvaluator, opts?: Partial | undefined): { type: string; description: string; f: SyntheticAttributeEvaluator; prev: never[]; opts: Partial; }; }; export declare function computableValue(d: AttributeDefinition, opts?: IComputedValueOptions): AttributeDefinition>; export declare function computable(d: AttributeDefinition, opts?: IComputedValueOptions): import("../kinds/definitions").TransformerAttributeDefinition, R>; /** * Make an existing synthetic attribute evaluator into a "computable" one. * Making it computable means that it can track observable data. The net effect * is that the attribute will now return an instance of `IComputedValue` which * lazily evaluates its result, memoizes the result AND automatically * invalidates the cached value if any of the values used to compute it were * changed! * @param f Original synthetic attribute evaluator * @returns */ export declare function computeableSynthetic(f: SyntheticAttributeEvaluator, options?: IComputedValueOptions): SyntheticAttributeEvaluator>; /** * Make an existing inherited attribute evaluator into a "computable" one. * Making it computable means that it can track observable data. The net effect * is that the attribute will now return an instance of `IComputedValue` which * lazily evaluates its result, memoizes the result AND automatically * invalidates the cached value if any of the values used to compute it were * changed! * @param f Original inherited attribute evaluator * @returns */ export declare function computeableInherited(f: InheritedAttributeEvaluator, options?: IComputedValueOptions): InheritedAttributeEvaluator>;