Interface Context<T>

A context.

interface Context<T> {
    apply<R>(fn, value): R;
    applyComputed<R>(fn, valueFn): R;
    get(node): T;
    getDefault(): T;
    getProviderNode(node): undefined | object;
    set(node, value): void;
    setComputed(node, valueFn): void;
    setDefault(value): void;
    setDefaultComputed(valueFn): void;
    unset(node): 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.

        • (): R
        • Returns R

    • value: T

      Value to apply.

    Returns R

    The value returned from the function.

    Typeparam

    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.

        • (): R
        • Returns R

    • valueFn: (() => T)
        • (): T
        • Returns T

    Returns R

    The value returned from the function.

    Typeparam

    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)
        • (): T
        • Returns T

    Returns void

  • Sets the context default value.

    Parameters

    • value: T

    Returns void

  • Sets the context default value resolver.

    Parameters

    • valueFn: (() => T)
        • (): T
        • Returns T

    Returns void

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

    Parameters

    • node: object

    Returns void