import { NodeDefinition, NodeLike, StatelessGraphNode, StatelessNodeDefinition, StatelessNodeType } from '../../types/graph'; /** * An instance of the [[ifPending]] node. * See the [[ifPending]] documentation to find out more. */ export interface IfPendingNode extends StatelessGraphNode<'ifPending', IfPendingNodeProperties> { } /** * A definition of the [[ifPending]] node. * See the [[ifPending]] documentation to find out more. */ export interface IfPendingNodeDefinition extends StatelessNodeDefinition<'ifPending', IfPendingNodeProperties> { } export declare type PendingFallbackGenerator = (previousValue: NodeDefinition | undefined) => NodeDefinition; export interface IfPendingNodeProperties { target: NodeDefinition; fallback: PendingFallbackGenerator | NodeDefinition | NodeLike; } /** * The implementation of the [[ifPending]]. * See the [[ifPending]] documentation to learn more. */ export declare const IfPendingNodeType: StatelessNodeType<'ifPending', IfPendingNodeProperties>; /** * Creates a new instance of a [[ifPending]] node, which is a type of a [[NodeDefinition]] used when there's a need * to always return a value for a certain node even if the `target` is not resolved (is pending). * This node is used by Muster-React to decide whether a certain query is loading. It works in a similar way to the * [[ifError]] with a difference that the [[ifError]] provides a fallback for the [[error]], while this * node provides a fallback for the [[pending]]. * * The `fallback` can be either a pre-defined [[NodeDefinition]] or a fallback generator. The fallback * generator receives a previous value the `target` was resolved to (undefined if this is the * first time `target` is being resolved) and is expected to return a [[NodeLike]]. * * * @example **Prevent `pending` state** * ```ts * import muster, { fromPromise, ifPending, ref, value } from '@dws/muster'; * * const app = muster({ * asyncName: fromPromise(() => Promise.resolve('Bob')), * syncName: ifPending( * (previous) => previous || value('Loading...'), * ref('asyncName'), * ), * }); * * app.resolve(ref('syncName')).subscribe((name) => { * console.log(name); * }); * * // Console output: * // Loading... * // Bob * ``` * This example shows how to use the [[ifPending]] to synchronously return a name. It makes sure * that the `asyncName` node does not block the query. */ export declare function ifPending(fallback: PendingFallbackGenerator | NodeDefinition | NodeLike, target: NodeDefinition | NodeLike): IfPendingNodeDefinition; export declare function isIfPendingNodeDefinition(value: NodeDefinition): value is IfPendingNodeDefinition;