import { GraphAction, GraphNode, NodeDefinition, NodeLike, StatefulGraphNode, StatefulNodeDefinition, StatefulNodeType } from '../../types/graph'; /** * An instance of the [[push]] node. * See the [[push]] documentation to find out more. */ export interface PushNode extends StatefulGraphNode<'push', PushNodeProperties> { } /** * A definition of the [[push]] node. * See the [[push]] documentation to find out more. */ export interface PushNodeDefinition extends StatefulNodeDefinition<'push', PushNodeProperties> { } export interface PushNodeProperties { item: NodeDefinition; target: NodeDefinition; } export interface PushNodeState { memoized: (targetNode: GraphNode, item: NodeDefinition) => GraphAction; } /** * The implementation of the [[push]]. * See the [[push]] documentation for more information. */ export declare const PushNodeType: StatefulNodeType<'push', PushNodeProperties, PushNodeState, {}>; /** * Creates an instance of an [[push]], which is a type of a graph node used when pushing a new item into a mutable collection. * It works in a similar way to `Array.push(...)` function from JavaScript. * * * @example **Push a number to a mutable collection** * ```js * import muster, { arrayList, entries, push, query, ref } from '@dws/muster'; * * const app = muster({ * numbers: arrayList([1, 2, 3]), * }); * * app.resolve(query(ref('numbers'), entries())).subscribe((value) => { * console.log(value); * }); * * await app.resolve(push(ref('numbers'), 5)); * * // Console output: * // [1, 2, 3] * // [1, 2, 3, 5] * ``` * This example shows how to add a new item at the end of a mutable collection. * * * @example **Push a branch to a mutable collection** * ```js * import muster, { arrayList, entries, key, push, query, ref, toNode } from '@dws/muster'; * * const app = muster({ * people: arrayList([ * { firstName: 'Lizzie', lastName: 'Ramirez' }, * { firstName: 'Charlotte', lastName: 'Schneider' }, * ]), * }); * * app.resolve(query(ref('people'), entries({ * firstName: key('firstName'), * }))).subscribe((value) => { * console.log(value); * }); * * await app.resolve( * push(ref('people'), toNode({ firstName: 'Genevieve', lastName: 'Patrick' })), * ); * * // Console output: * // [{ firstName: 'Lizzie' }, { firstName: 'Charlotte' }] * // [{ firstName: 'Lizzie' }, { firstName: 'Charlotte' }, { firstName: 'Genevieve' }] * ``` * This example shows how to add a new branch at the end of a mutable collection. */ export declare function push(target: NodeDefinition, item: NodeLike): PushNodeDefinition;