Abstract
Experimental
The type of target this extension will extend.
Static methods for working with extensions of the subclass type, e.g.
MyExt.for(someTarget)
.
Instance and static members you can override to customize extension creation, deletion, target and return types.
Static
__del__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.)
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.
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.)
Readonly
Experimental
ofThe 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.
Experimental
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.
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.:
You can then use
MyExt.for()
,.delete()
,.has()
, etc. on instances ofMyTargetType
, to manage theMyExt
instances attached to them.