the expected instance type
an instance of the loaded Javascript class
Extension subject declaration. Insert into the domain data to register a module export to be instantiated by an extension subject.
For example (assuming a m-ld clone
object):
clone.write(ExtensionSubject.declare(
'myCustomClass',
'my-custom-module',
'MyExtClass'
));
the CommonJS module (must be accessible using require
)
the constructor name exported by the module
Obtain an instance of a custom class declared in the data as the type of the given graph subject.
an ORM domain updating state to use for loading the type
the graph subject for which to obtain a custom subject instance
Generated using TypeDoc. Delivered by Vercel. @m-ld/m-ld - v0.9.1 Source code licensed MIT. Privacy policy
An extension subject defines a way to declare that subjects in the domain should be represented by a certain Javascript class.
Extension subjects can be declared using declare, and are used in one of two modes:
To load a singleton from a graph subject having type
http://js.m-ld.org/CommonJSExport
. In this case the extension subject (or a subclass) should be instantiated directly using {@link OrmUpdating#get}, and the singleton object obtained with singleton, e.g. with data:{ "@id": "myCustomSingleton", "@type": "http://js.m-ld.org/CommonJSExport", "http://js.m-ld.org/#require": "my-custom-module", "http://js.m-ld.org/#class": "MyExtClass" }
The single custom instance for this class might be loaded with:
const extType = orm.get('myCustomSingleton', src => new ExtensionSubject<MyExtType>({ src, orm }); const ext: MyExtType = extType.singleton;
To load an instance from a graph subject having a type that is itself of type
http://js.m-ld.org/CommonJSExport
. This indirection allows for many graph subjects to have custom type without re-declaring the module & export. The instance method is provided to load the instance, e.g. with data:{ "@id": "myCustomInstance", "@type": { "@id": "myCustomClass", "@type": "http://js.m-ld.org/CommonJSExport", "http://js.m-ld.org/#require": "my-custom-module", "http://js.m-ld.org/#class": "MyExtClass" } }
A custom instance for this class might be loaded with:
const ext: MyExtType = orm.get('myCustomInstance', src => ExtensionSubject.instance<MyExtType>({ src, orm });