import { GraphNode, NodeDefinition, NodeDependency, StatefulGraphNode, StatefulNodeDefinition, StatefulNodeType } from '../../types/graph'; /** * An instance of the [[once]] node. * See the [[once]] documentation to find out more. */ export interface OnceNode extends StatefulGraphNode<'once', OnceNodeProperties, OnceNodeState, OnceNodeData> { } /** * A definition of the [[once]] node. * See the [[once]] documentation to find out more. */ export interface OnceNodeDefinition extends StatefulNodeDefinition<'once', OnceNodeProperties, OnceNodeState, OnceNodeData> { } export interface OnceNodeProperties { target: NodeDefinition | GraphNode | NodeDependency; } export interface OnceNodeState { currentValue: NodeDefinition | GraphNode; } export interface OnceNodeData { } /** * The implementation of the [[once]] node. * See the [[once]] documentation to learn more. */ export declare const OnceNodeType: StatefulNodeType<'once', OnceNodeProperties, OnceNodeState, OnceNodeData>; /** * Creates a new instance of a [[once]], which is a type of a [[GraphNode]] that causes a given operation to be * performed only once. Used by the [[call]] node to prevent action from re-triggering every time a dependency is changed. * * * @example **Compute the value only once** * ```ts * import muster, { computed, once, ref, set, variable } from '@dws/muster'; * * const app = muster({ * name: variable('Bob'), * greeting: computed([once(ref('name'))], (name) => `Hello, ${name}`), * }); * * app.resolve(ref('greeting')).subscribe((greeting) => { * console.log(greeting); * }); * * console.log('Changing name to Jane'); * await app.resolve(set('name', 'Jane')); * * // Console output: * // Hello, Bob * // Changing name to Jane * ``` * This example shows how to use the [[once]] to ensure the value of a [[computed]] gets * computed only once and doesn't change when the `name` changes. */ export declare function once(target: NodeDefinition | GraphNode | NodeDependency): OnceNodeDefinition; export declare function isOnceNodeDefinition(value: NodeDefinition): value is OnceNodeDefinition;