the expected instance type
Utility property definition for CommonJs require
key
Override to provide custom post-initialisation behaviour
an instance of the loaded Javascript class
Override to provide custom pre-initialisation behaviour
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 ECMAScript module, must be accessible using import
the constructor name exported by the module
additional properties
Obtain an instance of a custom class declared in the data as the type of the given graph subject.
Generated using TypeDoc. Delivered by Vercel. @m-ld/m-ld - v0.10.0 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 a property
http://js.m-ld.org/#require
. In this case a SingletonExtensionSubject (or a subclass) should be instantiated directly using {@link OrmUpdating#get}, and the singleton object obtained with singleton, e.g. with data:{ "@id": "myCustomSingleton", "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 SingletonExtensionSubject<MyExtType>({ src, orm }); const ext: MyExtType = extType.singleton;
To load an instance from a graph subject that itself has the property type
http://js.m-ld.org/#require
. 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", "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 });