als-unhooked
    Preparing search index...

    Class ALSGlobal

    An extension of ALS that also acts as a singleton instance through same-named static methods. The singleton pattern is convenient for basic applications that don't need multiple stores.

    import als from 'als-unhooked/modern';

    // Using as a singleton
    als.run(() => {
    als.set('key', 'foo');
    console.log(als.get('key')); // Output: 'foo'
    });

    // Using as a constructor
    const alsInstance = new als();
    alsInstance.run(() => {
    alsInstance.set('key', 'bar');
    console.log(alsInstance.get('key')); // Output: 'bar'
    });

    The type of keys in the store.

    The type of values in the store.

    Hierarchy (View Summary)

    • ALS<any, any>
      • ALSGlobal
    Index

    Constructors

    Static Methods

    Instance Methods

    Properties

    Constructors

    Static Methods

    • Retrieves the current store.

      Type Parameters

      • T extends Map<any, any> = Map<any, any>

      Returns T

      The current store or undefined if there is no store.

    • Retrieves a value from the store by key.

      Parameters

      • key: any

      Returns any

      The value associated with the key, or undefined if the key does not exist.

    • Sets a value in the store by key.

      Parameters

      • key: any
      • value: any

      Returns void

    • Runs a function within a new store context.

      Type Parameters

      • T

      Parameters

      Returns T

      The result of the function.

    • Experimental

      Exits the current store context and runs a function. Marked experimental as it depends on AsyncLocalStorage#exit

      Type Parameters

      • T

      Parameters

      • fn: () => T

      Returns T

      The result of the function.

    • For a given function, creates a bound function that has the same body as the original function. The this object of the bound function is associated with the specified object, and has the specified initial parameters.

      Type Parameters

      • T extends () => any

      Parameters

      • fn: T

      Returns T

    Instance Methods

    • Runs a function within a new store context.

      Type Parameters

      • T

      Parameters

      • fn: () => T

        The function to run.

      • Optionaldefaults: Dictionary<any, any>

        The default values to initialize the store with.

      Returns T

      The result of the function.

    • Experimental

      Exits the current store context and runs a function. Marked experimental as it depends on AsyncLocalStorage#exit

      Type Parameters

      • T

      Parameters

      • fn: () => T

        The function to run.

      Returns T

      The result of the function.

    • Experimental

      Binds a function to the current store context. Marked experimental as it depends on AsyncLocalStorage.bind

      Type Parameters

      • T extends () => any

      Parameters

      • fn: T

        The function to bind.

      Returns T

      The bound function.

    • Retrieves the current store.

      Returns undefined | Map<any, any>

      The current store or undefined if there is no store.

    • Retrieves a value from the store by key.

      Type Parameters

      • T extends any = any

      Parameters

      • key: any

        The key to retrieve the value for.

      Returns undefined | T

      The value associated with the key, or undefined if the key does not exist.

    • Sets a value in the store by key.

      Type Parameters

      • T extends any = any

      Parameters

      • key: any

        The key to set the value for.

      • value: T

        The value to set.

      Returns void

    Properties

    d: Object = ...
    asyncLocalStorage: AsyncLocalStorage<Map<any, any>>