Uneventful
    Preparing search index...

    Class Ext<Target>Abstract Experimental

    A base class for more complex extension types, providing static accessor and management APIs. (e.g. MyExt.for(aTarget), MyExt.delete(aTarget), etc.)

    To create an extension class, just subclass Ext with an appropriate target type, e.g.:

    class MyExt extends Ext<MyTargetType> {
    // ...
    }

    You can then use MyExt.for(), .delete(), .has(), etc. on instances of MyTargetType, to manage the MyExt instances attached to them.

    Type Parameters

    • Target extends WeakKey = WeakKey

      The type of target this extension will extend.

    Index

    Extension Management

    Static methods for working with extensions of the subclass type, e.g. MyExt.for(someTarget).

    Lifecycle Hooks

    Instance and static members you can override to customize extension creation, deletion, target and return types.

    Other

    Extension Management

    Lifecycle Hooks

    • Experimental

      This method is called by delete() if it finds an existing extension for the target. You can override it in a subclass to do any necessary cleanup on the extension. (If you need to retrieve the extension, you can call .get() on the target.)

      Type Parameters

      • Class extends typeof Ext

      Parameters

      Returns void

    • Experimental

      Given a target, create an extension instance.

      You do not need to override this, nor should you: it's just a type-safe way to construct an extension instance, since an Ext subclass's constructor may accept a wider type than the class actually requires.

      Type Parameters

      • T extends Ext<object>

      Parameters

      • this: T
      • tgt: T["of"]

      Returns T

    • Experimental

      This method is called by for() to create the extension instance for a target. You can override this method to customize instance creation behavior, e.g. to execute the constructor within a job, or create a promise for an extension instance to be asynchronously initiaized, etc.

      For example:

      class AsyncExt extends Ext<SomeType> {
      // simulate slow initialization
      *setup() { yield *sleep(100); return this; }

      __new__(tgt: SomeType): Job<this> {
      const ext = this.__inst__(tgt);
      map.set(tgt, root.start(ext.setup()) as Ext.Type<Class>);
      }
      }

      Now, AsyncExt.for(someTarget) will create and cache a Job yielding an extension whose setup() has finished. (And subclasses of AsyncExt will share the same behavior, while being subtyped appropriately.)

      Type Parameters

      • C extends Ext<object>

      Parameters

      • this: C
      • tgt: C["of"]

      Returns unknown

      Note that while this is technically an instance method, it's actually called with the class prototype, so you should not use any properties or methods of this other than __inst__. Think of it as a function that's just on the class as a convenient way of configuring it.

    of: Target

    The target the extension was created for (set automatically by the base class constructor). You can narrow the target type either by extending Ext<SomeType> directly, or by using declare readonly of: SomeType in your subclass.

    Other

    • Experimental

      Type Parameters

      • Target extends object = object

      Parameters

      Returns Ext<Target>

      Use .for() or prototype.__inst__() instead!

      Never directly call the constructor of an Ext subclass. If you're creating an instance in __new__(), use the __inst__() method instead. Otherwise, you should use the .for or .get methods, as they are properly typed and won't create multiple instances for the same target.