import { Maybe } from "purify-ts/Maybe"; import { ListChildren } from "../children"; import { ArborEmitter, MutationEvents, MutationMonitor } from "../events"; import { Attribute } from "../kinds/attributes"; import { SyntheticAttributeDefinition, InheritedAttributeDefinition } from "../kinds/definitions"; import { ParentFunc } from "../kinds/inherited"; import { ReificationOptions } from "../kinds/options"; import { Reifier } from "./reifier"; export interface MobxReifierOptions extends ReificationOptions { computed: { requiresReaction?: boolean; keepAlive?: boolean; }; } /** * 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 class MobxReifier implements Reifier { protected dummy: import("typed-emitter").default>; protected options: Partial; constructor(opts?: Partial); parent(root: T, list: ListChildren, monitor: MutationMonitor): Attribute>; synthetic(root: T, list: ListChildren, def: SyntheticAttributeDefinition, emitter: ArborEmitter, monitor: MutationMonitor, opts: Partial): Attribute; inherited(root: T, list: ListChildren, def: InheritedAttributeDefinition, emitter: ArborEmitter, monitor2: MutationMonitor, p: ParentFunc, opts: Partial): Attribute; protected computedOptions(): { keepAlive: boolean; requiresReaction: boolean; }; protected reificationOptions(opts?: Partial): ReificationOptions; }