1.0.0

interface ContextManager {
    active(): Context;
    bind<T>(context?: Context, target: T): T;
    disable(): this;
    enable(): this;
    with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(
        context: Context,
        fn: F,
        thisArg?: ThisParameterType<F>,
        ...args: A,
    ): ReturnType<F>;
}

Implemented by

Methods

  • Bind an object as the current context (or a specific one)

    Type Parameters

    • T

    Parameters

    • Optionalcontext: Context

      Optionally specify the context which you want to assign

    • target: T

      Any object to which a context need to be set

    Returns T

  • Run the fn callback with object set as the current active context

    Type Parameters

    • A extends unknown[]
    • F extends (...args: A) => ReturnType<F>

    Parameters

    • context: Context

      Any object to set as the current active context

    • fn: F

      A callback to be immediately run within a specific context

    • OptionalthisArg: ThisParameterType<F>

      optional receiver to be used for calling fn

    • ...args: A

      optional arguments forwarded to fn

    Returns ReturnType<F>