Interface Context<T>

A context.

interface Context<T> {
    apply<R>(fn: () => R, value: T): R;
    applyComputed<R>(fn: () => R, valueFn: () => T): R;
    get(node: object): T;
    getDefault(): T;
    getProviderNode(node: object): undefined | object;
    set(node: object, value: T): void;
    setComputed(node: object, valueFn: () => T): void;
    setDefault(value: T): void;
    setDefaultComputed(valueFn: () => T): void;
    unset(node: object): void;
}

Type Parameters

  • T

Methods

  • Applies a value override while the given function is running and, if a node is returned, sets the node as a provider of the value.

    Type Parameters

    • R

    Parameters

    • fn: () => R

      Function to run.

    • value: T

      Value to apply.

    Returns R

    The value returned from the function.

    R

  • Applies a computed value override while the given function is running and, if a node is returned, sets the node as a provider of the computed value.

    Type Parameters

    • R

    Parameters

    • fn: () => R

      Function to run.

    • valueFn: () => T

    Returns R

    The value returned from the function.

    R

  • Gets the context value for a given node.

    Parameters

    • node: object

    Returns T

  • Gets the context default value.

    Returns T

  • Gets node that will provide the context value, or undefined if it comes from the default.

    Parameters

    • node: object

    Returns undefined | object

  • Sets the context value for a given node, effectively making it a provider.

    Parameters

    • node: object
    • value: T

    Returns void

  • Sets the context value resolver for a given node, effectively making it a provider.

    Parameters

    • node: object
    • valueFn: () => T

    Returns void

  • Sets the context default value.

    Parameters

    • value: T

    Returns void

  • Sets the context default value resolver.

    Parameters

    • valueFn: () => T

    Returns void

  • Unsets the context value for a given node, therefore it won't be a provider anymore.

    Parameters

    • node: object

    Returns void