import { ObservableLike, Subscription } from '@dws/muster-observable'; import { GraphNode, NodeDefinition, StatefulGraphNode, StatefulNodeType } from '../../types/graph'; /** * An instance of the [[stateful]] node. * See the [[stateful]] documentation to find out more. */ export interface ExternalStatefulNode extends StatefulGraphNode<'stateful', ExternalStatefulNodeProperties, ExternalStatefulNodeState, ExternalStatefulNodeData> { } /** * A definition of the [[stateful]] node. * See the [[stateful]] documentation to find out more. */ export interface ExternalStatefulNodeDefinition extends NodeDefinition<'stateful', ExternalStatefulNodeProperties, ExternalStatefulNodeState, ExternalStatefulNodeData> { update(value: V): void; } export interface ExternalStatefulNodeProperties { valueStream: ObservableLike; } export interface ExternalStatefulNodeState { currentValue: NodeDefinition | GraphNode; } export interface ExternalStatefulNodeData { subscription: Subscription | undefined; } /** * The implementation of the [[stateful]] node. * See the [[stateful]] documentation to learn more. */ export declare const ExternalStatefulNodeType: StatefulNodeType<'stateful', ExternalStatefulNodeProperties, ExternalStatefulNodeState>; /** * Creates a new instance of a [[stateful]] node, which is useful when you need to create a graph node that can be changed * from outside Muster. It works in the same way as a [[fromStream]] with the * `BehaviourSubject` from RxJS. * * * @example **Simple stateful node** * ```ts * import muster, { computed, ref, stateful } from '@dws/muster'; * * const isOffline = stateful(false); * const app = muster({ * isOffline, * status: computed([ref('isOffline')], (isOffline) => * isOffline ? 'Offline' : 'Online', * ), * }); * * app.resolve(ref('status')).subscribe((status) => { * console.log(status); * }); * * console.log('Changing isOffline to true'); * isOffline.update(true); * * // Console output: * // Online * // Changing isOffline to true * // Offline * ``` * This example shows how to use a [[stateful]] to send values to Muster. */ export declare function stateful(initialValue: V): ExternalStatefulNodeDefinition; export declare function isStatefulNodeDefinition(value: NodeDefinition): value is ExternalStatefulNodeDefinition;