import { GraphAction, GraphNode, NodeDefinition, NodeLike, StatefulGraphNode, StatefulNodeDefinition, StatefulNodeType } from '../../types/graph'; /** * An instance of the [[addItemAt]] node. * See the [[addItemAt]] documentation to find out more. */ export interface AddItemAtNode extends StatefulGraphNode<'add-item-at', AddItemAtNodeProperties> { } /** * A definition of the [[addItemAt]] node. * See the [[addItemAt]] documentation to find out more. */ export interface AddItemAtNodeDefinition extends StatefulNodeDefinition<'add-item-at', AddItemAtNodeProperties> { } export interface AddItemAtNodeProperties { index: NodeDefinition; item: NodeDefinition; target: NodeDefinition; } export interface AddItemAtNodeState { memoized: (targetNode: GraphNode, item: NodeDefinition, index: number) => GraphAction; } /** * The implementation of the [[addItemAt]] node. * See the [[addItemAt]] documentation for more information. */ export declare const AddItemAtNodeType: StatefulNodeType<'add-item-at', AddItemAtNodeProperties, AddItemAtNodeState, {}>; /** * Creates an instance of an [[addItemAt]] node, which is a type of a graph node used when inserting an item into * a mutable collection at a specific index. * * * @example **Insert a number to a mutable collection** * ```js * import muster, { addItemAt, arrayList, entries, 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(addItemAt(ref('numbers'), 5, 1)); * * // Console output: * // [1, 2, 3] * // [1, 5, 2, 3] * ``` * This example shows how to insert a new item to a mutable collection. * * * @example **Insert a branch to a mutable collection** * ```js * import muster, { addItemAt, arrayList, entries, key, 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( * addItemAt(ref('people'), toNode({ firstName: 'Genevieve', lastName: 'Patrick' }), 1), * ); * * // Console output: * // [{ firstName: 'Lizzie' }, { firstName: 'Charlotte' }] * // [{ firstName: 'Lizzie' }, { firstName: 'Genevieve' }, { firstName: 'Charlotte' }] * ``` * This example shows how to insert a new branch to a mutable collection. */ export declare function addItemAt(target: NodeDefinition, item: NodeLike, index: NodeLike): AddItemAtNodeDefinition;