import { Orderable } from "./bufferedqueue.js"; import { Extent } from "./extent.js"; import { Resource, Demandable } from "./resource.js"; import { RelinkingOrder } from "./common.js"; /** * A block of code together with the resources it demands and supplies. Create one with * `extent.behavior()...runs(block)`; the graph runs it in any event in which a demand updated, * after the suppliers of its demands. Never call it directly. */ export declare class Behavior implements Orderable { /** The resources this behavior is linked to as demands, static and dynamic, including `.order` ones. Null until linked. */ demands: Set | null; /** The subset of `demands` that are `.order` demands. */ orderingDemands: Set | null; /** The states declared with `.trace`. These are not edges. */ traceDemands: Set | null; /** The resources this behavior supplies, static and dynamic. Null until linked. */ supplies: Set | null; /** The extent this behavior belongs to. */ extent: Extent; /** Topological rank: a behavior runs after every behavior with a lower order that it depends on. */ order: number; constructor(extent: Extent, demands: Demandable[] | null, supplies: Resource[] | null, block: (extent: Extent) => void); toString(): string; /** Replaces this behavior's dynamic demands. Usually done for you by `dynamicDemands` on the builder. */ setDynamicDemands(newDemands: (Demandable | undefined)[] | null): void; /** Replaces this behavior's dynamic supplies. Usually done for you by `dynamicSupplies` on the builder. */ setDynamicSupplies(newSupplies: (Resource | undefined)[] | null): void; } /** Builds a {@link Behavior}. Get one from `extent.behavior()` and finish with `runs`. */ export declare class BehaviorBuilder { constructor(extent: T); /** * Adds demands: the behavior runs in any event in which one of these updated (except `.order` * and `.trace` demands) and may read them. A second call adds to the list. */ demands(...demands: Demandable[]): this; /** Adds resources this behavior supplies (is the only one allowed to update). A second call adds to the list. */ supplies(...supplies: Resource[]): this; /** * Demands that change at runtime. Whenever a resource in `switches` updates, `links` runs and * its result replaces the behavior's dynamic demands. With the default * {@link RelinkingOrder.relinkingOrderPrior} the relink happens before the behavior runs; use * relinkingOrderSubsequent when the behavior supplies a switch itself. `undefined` entries are * dropped. May be called once per behavior. */ dynamicDemands(switches: Demandable[], links: ((ext: T) => (Demandable | undefined)[] | null), relinkingOrder?: RelinkingOrder): this; /** * Supplies that change at runtime, relinked like {@link BehaviorBuilder.dynamicDemands}. May * be called once per behavior. */ dynamicSupplies(switches: Demandable[], links: ((ext: T) => (Resource | undefined)[] | null), relinkingOrder?: RelinkingOrder): this; /** Finishes the behavior with the code to run. `block` receives the extent; inside it, read only demanded or supplied resources and update only supplied ones. */ runs(block: (ext: T) => void): Behavior; }