import { CallArgumentArray, CallArgumentMap, NodeLikeCallArgumentArray, NodeLikeCallArgumentMap } from '../../operations/call'; import { GraphNode, NodeDefinition, NodeLike, StatefulGraphNode, StatefulNodeDefinition, StatefulNodeType } from '../../types/graph'; import { RootAndPath } from '../../utils/ref'; /** * An instance of the [[call]] node. * See the [[call]] documentation to find out more. */ export interface CallNode extends StatefulGraphNode<'call', CallNodeProperties, CallNodeState, CallNodeData> { } /** * A definition of the [[call]] node. * See the [[call]] documentation to find out more. */ export interface CallNodeDefinition extends StatefulNodeDefinition<'call', CallNodeProperties, CallNodeState, CallNodeData> { } export interface CallNodeProperties { args: CallArgumentArray | CallArgumentMap | undefined; target: NodeDefinition; } export interface CallNodeState { currentValue: NodeDefinition | GraphNode; } export interface CallNodeData { } /** * The implementation of a [[call]] node. * See the [[call]] documentation for more information. */ export declare const CallNodeType: StatefulNodeType<'call', CallNodeProperties, CallNodeState, CallNodeData>; /** * Creates a new instance of a [[call]] node, which is a node used when calling a [[NodeDefinition]] that implements a `call` method, e.g. [[action]], * [fn](_nodes_graph_fn_.html#fn) or [[placeholder]]. Unlike the [[apply]], the [[call]] calls the * body of the callable node only once per subscription. Multiple subscriptions to the [[call]] * cause multiple executions of the callable node body. This imitates standard JavaScript function calls and can be * used when responding to button clicks or events in applications. * * * @example **Call an action** * ```ts * import muster, { action, call } from '@dws/muster'; * * const app = muster({ * logSomething: action(() => { * console.log('Action called'); * }), * }); * * console.log('Calling the action'); * const result = await app.resolve(call('logSomething')); * // result === undefined * * // Console output: * // Calling the action * // Action called * ``` * This example shows how to call a basic [[action]]. You can learn more about the [[action]] in its documentation. * * * @example **Call an fn node** * ```ts * import muster, { call, fn, value } from '@dws/muster'; * * const app = muster({ * getGreeting: fn(() => value('Hello world')), * }); * * console.log('Calling the fn'); * const result = await app.resolve(call('getGreeting')); * // result === 'Hello world' * * console.log(result); * * // Console output: * // Calling the fn * // Hello world * ``` * This example shows how to call a basic [fn](_nodes_graph_fn_.html#fn). * You can learn more about the [fn](_nodes_graph_fn_.html#fn) in its documentation. * * * @example **Call with arguments** * ```ts * import muster, { action, call, ref } from '@dws/muster'; * * const app = muster({ * lastName: 'Franklin', * getFullName: action((firstName, lastName) => `${firstName} ${lastName}`), * }); * * console.log('Calling the action'); * const result = await app.resolve( * call('getFullName', ['Rosalind', ref('lastName')]) * ); * // result === 'Rosalind Franklin' * * console.log(result); * * // Console output: * // Calling the action * // Rosalind Franklin * ``` * This example shows how to supply arguments to the called [[action]] - the same can be done * with the [fn](_nodes_graph_fn_.html#fn). There are no restrictions on the type of the arguments. When Muster * encounters an argument that is not a [[NodeDefinition]], an automatic conversion with the [[toValue]] * helper occurs. An argument that is already A type of [[NodeDefinition]] is resolved to its most * basic form before calling the action. * * * @example **Multiple consecutive calls** * ```js * import muster, { action, call } from '@dws/muster'; * * const app = muster({ * logWhenCalled: action(() => { * console.log('Action called'); * }), * }); * * console.log('First call:') * app.resolve(call('logWhenCalled')).subscribe(() => {}); * * console.log('Second call:'); * app.resolve(call('logWhenCalled')).subscribe(() => {}); * * // Console output: * // First call: * // Action called * // Second call: * // Action called * ``` * This example shows that the [[call]] node runs the body of an action every time a [[call]] is resolved. */ export declare function call(rootAndPathInput: RootAndPath): CallNodeDefinition; export declare function call(rootAndPathInput: RootAndPath, args: NodeLikeCallArgumentArray): CallNodeDefinition; export declare function call(rootAndPathInput: RootAndPath, args: NodeLikeCallArgumentMap): CallNodeDefinition; export declare function call(target: NodeDefinition): CallNodeDefinition; export declare function call(target: NodeDefinition, args: NodeLikeCallArgumentArray): CallNodeDefinition; export declare function call(target: NodeDefinition, args: NodeLikeCallArgumentMap): CallNodeDefinition; export declare function call(root: NodeDefinition, path: Array, args: NodeLikeCallArgumentArray): CallNodeDefinition; export declare function call(root: NodeDefinition, path: Array, args: NodeLikeCallArgumentMap): CallNodeDefinition; export declare function call(path: NodeLike | Array): CallNodeDefinition; export declare function call(path: NodeLike | Array, args: NodeLikeCallArgumentArray): CallNodeDefinition; export declare function call(path: NodeLike | Array, args: NodeLikeCallArgumentMap): CallNodeDefinition; export declare function isCallNodeDefinition(value: NodeDefinition): value is CallNodeDefinition;