import { ContextName, GraphNode, NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../types/graph'; /** * An instance of the [[injectDependencies]] node. * See the [[injectDependencies]] documentation to find out more. */ export interface InjectDependenciesNode extends StatelessGraphNode<'inject-dependencies', InjectDependenciesNodeProperties> { } /** * A definition of the [[injectDependencies]] node. * See the [[injectDependencies]] documentation to find out more. */ export interface InjectDependenciesNodeDefinition extends StatelessNodeDefinition<'inject-dependencies', InjectDependenciesNodeProperties> { } export interface InjectDependenciesNodeProperties { context?: { [key in ContextName]: NodeDefinition; }; dependencies: Array; target: T; } /** * An implementation of the [[injectDependencies]] node. * See the [[injectDependencies]] documentation to find out more. */ export declare const InjectDependenciesNodeType: StatelessNodeType<'inject-dependencies', InjectDependenciesNodeProperties>; /** * Creates a new instance of the [[injectDependencies]] node, which can be used when creating partially resolved nodes. * This node allows supplying some or all of the context and node dependencies of a given node. * * * @example **Call inject dependencies on a computed node - no injected dependencies** * ```js * import muster, { * computed, * injectDependencies, * ref, * } from '@dws/muster'; * * const app = muster({ * two: 2, * four: 4, * }); * * await app.resolve(injectDependencies( * computed( * [ref('four'), ref('two')], * (left, right) => left * right, * ), * [], // Dependencies to override * )); // === 8 * ``` * In this example we have created a computed node with two dependencies: * - ref('four') * - ref('two') * * When resolved against the graph above this produces 8. Because in our example we have not overridden any dependencies * through the `injectDependencies`, the node end up resolving to 8 as well. * * * @example **Call inject dependencies on a computed node - change both dependencies** * ```js * import muster, { * computed, * injectDependencies, * ref, * value, * } from '@dws/muster'; * * const app = muster({ * two: 2, * four: 4, * }); * * await app.resolve(injectDependencies( * computed( * [ref('four'), ref('two')], * (left, right) => left * right, * ), * [value(5), value(3)], // Dependencies to override * )); // === 15 * ``` * This example re-uses the code from the previous example with a notable difference of having defined dependency overrides. * Note that the values used as overrides are now 5 and 3. Due to the way the [[computed]] node is implemented * the order of these values matches the order of arguments in the `combine` function of the computed, meaning that * `left = 5` and `right = 3`. * * * @example **Call inject dependencies on a computed node - change only the last argument** * ```js * import muster, { * computed, * injectDependencies, * ref, * value, * } from '@dws/muster'; * * const app = muster({ * two: 2, * four: 4, * }); * * await app.resolve(injectDependencies( * computed( * [ref('four'), ref('two')], * (left, right) => left * right, * ), * [undefined, value(3)], // Dependencies to override * )); // === 12 * ``` * Apart from being able to override all dependencies, [[injectDependencies]] node enables the developers with ability to * override a specific dependency. In the example code above the first dependency was set to `undefined`, which tells * the [[injectDependencies]] node that this is not a real value, and it should resolve it as normally, but the second * dependency is defined. This means that the `combine` function of the [[computed]] node is called with * `left = ref('four') => 4` and `right = 3`. */ export declare function injectDependencies(target: NodeDefinition, dependencies: Array, context?: { [name: string]: NodeDefinition | NodeLike; }): InjectDependenciesNodeDefinition; export declare function isInjectDependenciesNodeDefinition(value: NodeDefinition): value is InjectDependenciesNodeDefinition;