nope/lib/loader/generateNopeBasicPackage.ts
2020-11-23 07:09:31 +01:00

79 lines
2.6 KiB
TypeScript

/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-11-07 17:24:34
* @modify date 2020-11-14 17:32:43
* @desc [description]
*/
import { nopeDispatcher } from "../dispatcher/nopeDispatcher";
import { NopeObservable } from "../observables/nopeObservable";
import { COMMUNICATION_LAYER, DISPATCHER_INSTANCE, DISPATCHER_OPTIONS, OBSERVABLE_FACTORY, OBSERVABLE_INSTANCE } from '../symbols/identifiers';
import { ICommunicationInterface, INopeDispatcherOptions } from "../types/nope/nopeCommunication.interface";
import { IPackageDescription } from "../types/nope/nopePackage.interface";
/**
* Generates the Default Package, containing all relevant elements of the
* nope-package. Provide the utilized communication layer.
*
* @export
* @param {ICommunicationInterface} communicationLayer The Layer, which should be used.
* @return {*}
*/
export function generateNopeBasicPackage(options: INopeDispatcherOptions) {
const TYPES = {
dispatcher: DISPATCHER_INSTANCE,
observableFactory: OBSERVABLE_FACTORY,
observable: OBSERVABLE_INSTANCE,
communicationLayer: COMMUNICATION_LAYER,
dispatcherOptions: DISPATCHER_OPTIONS,
}
const definedPackage: IPackageDescription<typeof TYPES> = {
activationHandlers: [],
autostart: {},
defaultInstances: [],
nameOfPackage: 'nopeBasicPackage',
providedClasses: [
{
description: {
name: 'nopeDispatcher',
selector: TYPES.dispatcher,
type: nopeDispatcher
},
settings: {
allowInstanceGeneration: false,
}
},
{
description: {
name: 'communicationLayer',
selector: TYPES.dispatcherOptions,
type: options,
options: {
toConstant: true
}
},
settings: {
allowInstanceGeneration: false,
}
},
{
description: {
name: 'nopeObservable',
selector: TYPES.observable,
factorySelector: TYPES.observableFactory,
type: NopeObservable
},
settings: {
allowInstanceGeneration: false,
}
}
],
providedFunctions: [],
requiredPackages: [],
types: TYPES
}
return definedPackage;
}