import { NodeDefinition, NodeLike, StatefulGraphNode, StatefulNodeDefinition, StatefulNodeType } from '../../types/graph'; import { RootAndPath } from '../../utils/ref'; /** * An instance of the [[invalidate]] node. * See the [[invalidate]] documentation to find out more. */ export interface InvalidateNode extends StatefulGraphNode<'invalidate', InvalidateNodeProperties> { } /** * A definition of the [[invalidate]] node. * See the [[invalidate]] documentation to find out more. */ export interface InvalidateNodeDefinition extends StatefulNodeDefinition<'invalidate', InvalidateNodeProperties> { } export interface InvalidateNodeProperties { target: NodeDefinition; } export interface InvalidateNodeState { } export interface InvalidateNodeData { } /** * The implementation of the [[invalidate]]. * See the [[invalidate]] documentation to learn more. */ export declare const InvalidateNodeType: StatefulNodeType<'invalidate', InvalidateNodeProperties>; /** * Creates a new instance of an [[invalidate]] node, which is a type of [[NodeDefinition]] used to trigger the * invalidation mechanism. Invalidation causes the target node to lose its value and forces a re-fetch of it. * This is particularly useful for nodes like [[fromPromise]] or [[computed]] that can * change value depending on external factors - e.g. calling an API endpoint or some local variable in the code * (which is not recommended). * * The invalidation mechanism can also be triggered upon dispatching a Muster event with the help of the * [[invalidateOn]]. See the [[dispatch]] to learn more about Muster events. * * * @example **Invalidate a fromPromise node** * ```ts * import muster, { fromPromise, invalidate, ref } from '@dws/muster'; * * const externalNumbers = [1, 2, 3]; * * const app = muster({ * numbers: fromPromise(() => Promise.resolve(externalNumbers)), * }); * * app.resolve(ref('numbers')).subscribe((numbers) => { * console.log(numbers); * }); * * console.log('Adding `4` to numbers`'); * externalNumbers.push(4); * * console.log('Invalidating `numbers`'); * await app.resolve(invalidate(ref('numbers'))); * * // Console output: * // [1, 2, 3] * // Adding `4` to numbers` * // Invalidating `numbers` * // [1, 2, 3, 4] * ``` * This example shows how to use the [[invalidate]] to force re-fetching of a new value of the * targeted node. This particular example stores the data in a local variable, but nothing * prevents forcing an API re-fetch. This can be done in exactly the same way as in the * example above. */ export declare function invalidate(rootAndPath: RootAndPath): InvalidateNodeDefinition; export declare function invalidate(target: NodeDefinition): InvalidateNodeDefinition; export declare function invalidate(root: NodeDefinition, path: NodeLike | Array): InvalidateNodeDefinition; export declare function invalidate(...path: Array): InvalidateNodeDefinition; export declare function isInvalidateNodeDefinition(value: NodeDefinition): value is InvalidateNodeDefinition;