Options
All
  • Public
  • Public/Protected
  • All
Menu

Module LazyProxy

Lazy initializer proxy factory

Index

Functions

Functions

create

  • create<T>(init: function, isConstructor?: undefined | false | true): T
  • Create a proxy object which loosely reflects to the target object of a delayed (lazy) initializer.

    example
    const somethingExpensive = LazyProxy.create(() => {
      // Some heavy stuffs...
      return someHeavyObject;
    });
    
    // You may treat the object is loosely equals to the initialized object itself.
    const someValue = somethingExpensive.someValue();

    Type parameters

    • T

    Parameters

    • init: function

      The lazy initializer which returns the object.

        • (): T
        • Returns T

    • Optional isConstructor: undefined | false | true

      Whether the target object will be a constructor and the proxy will use as constructor directly or not. This will use a alternative flow with some minor drawbacks to provide constructor support.

    Returns T

getSource

  • getSource<T>(maybeProxy: T): T
  • Get the target source object of a proxy. Will returns itself if not found. If the initializer is not yet resolved, it will resolves immediately.

    Type parameters

    • T

    Parameters

    • maybeProxy: T

      The wrapped proxy.

    Returns T

Generated using TypeDoc