import { GraphAction, GraphNode, NodeDefinition, NodeLike, StatefulGraphNode, StatefulNodeDefinition, StatefulNodeType } from '../../types/graph'; /** * An instance of the [[unshift]] node. * See the [[unshift]] documentation to find out more. */ export interface UnshiftNode extends StatefulGraphNode<'unshift', UnshiftNodeProperties> { } /** * A definition of the [[unshift]] node. * See the [[unshift]] documentation to find out more. */ export interface UnshiftNodeDefinition extends StatefulNodeDefinition<'unshift', UnshiftNodeProperties> { } export interface UnshiftNodeProperties { item: NodeDefinition; target: NodeDefinition; } export interface UnshiftNodeState { memoized: (targetNode: GraphNode, item: NodeDefinition) => GraphAction; } /** * The implementation of the [[unshift]]. * See the [[unshift]] documentation for more information. */ export declare const UnshiftNodeType: StatefulNodeType<'unshift', UnshiftNodeProperties, UnshiftNodeState, {}>; /** * Creates an instance of an [[unshift]], which is a type of a graph node used when unshifting a new item into a mutable collection. * It works in a similar way to `Array.unshift(...)` function from JavaScript. * * * @example **Unshift a number to a mutable collection** * ```js * import muster, { arrayList, entries, unshift, 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(unshift(ref('numbers'), 5)); * * // Console output: * // [1, 2, 3] * // [5, 1, 2, 3] * ``` * This example shows how to add a new item at the beginning of a mutable collection. * * * @example **Unshift a branch to a mutable collection** * ```js * import muster, { arrayList, entries, key, unshift, 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( * unshift(ref('people'), toNode({ firstName: 'Genevieve', lastName: 'Patrick' })), * ); * * // Console output: * // [{ firstName: 'Lizzie' }, { firstName: 'Charlotte' }] * // [{ firstName: 'Genevieve' }, { firstName: 'Lizzie' }, { firstName: 'Charlotte' }] * ``` * This example shows how to add a new branch at the beginning of a mutable collection. */ export declare function unshift(target: NodeDefinition, item: NodeLike): UnshiftNodeDefinition;