Assembly: Readonly<SingletonKosModelRegistrationBean<AssemblyModel, AssemblyOptions>> = ...

Assembly

The registration bean includes convenience methods for creating and working with AssemblyModel instances.

type

The type property is a string that identifies the model type. The type is used to identify the model type in the model registry and to narrow down the model type in type predicates. It's most frequently used when declaring dependencies on models.

Example


@kosDependency({modelType: Assembly.type, id: "assemblyId"})
private assemblyModel: AssemblyModel;

factory

The factory method creates a factory function that can be used to create new AssemblyModel instances.

The factory function is a curried function that takes the model id as the first argument and the options as the second argument.

If a model with the specified id already exists, the factory function will return the existing model. The options will be ignored in this case and the existing model will be returned in its current state.

Example

const model = Assembly.factory("assemblyId")({
// Add option data
});

predicate

Typescript type predicate function that will identify and narrow down a model to a AssemblyModel.

Example


const model: IKosDataModel = ...; // some model

if (Assembly.predicate(model)) {
// if the function evaluates to true, the model is narrowed down to AssemblyModel
// and the compiler will know that the model has the AssemblyModel interface
model.updateAvailability(false);
}

registration

The registration property is an object that can be used to simplify registration of the model with the model registry. The registration object can be spread into the model registration and provides all of the required information to register the model implementation class against the model type.

Example

In an application registration file you can declare the model registration as follows:

registration.ts

import { Assembly } from "@kosdev-code/kos-dispense-sdk";
...
import { ExtensionManager, IKosRegistry } from "@kosdev-code/kos-ui-sdk";
export const kosModels: IKosRegistry["models"] = {
...Assembly.registration,
};

registration.singleton

The assembly model is a singleton model. This means that each time the factory function the same instance of the model will be returned.