nope/lib/loader/generateNopeBasicPackage.ts

121 lines
3.4 KiB
TypeScript
Raw Normal View History

2020-11-07 00:45:20 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @desc [description]
*/
import { decorate, injectable } from "inversify";
import { getDispatcher } from "../dispatcher/getDispatcher";
import { NopeDispatcher } from "../dispatcher/nopeDispatcher";
import { InjectableNopeEventEmitter } from "../eventEmitter";
import { NopeBaseModule } from "../module/BaseModule";
2020-11-07 00:45:20 +00:00
import { NopeObservable } from "../observables/nopeObservable";
import { InjectableNopeObservable } from "../observables/nopeObservable.injectable";
import {
COMMUNICATION_LAYER,
DISPATCHER_INSTANCE,
DISPATCHER_OPTIONS,
EMITTER_FACTORY,
EMITTER_INSTANCE,
OBSERVABLE_FACTORY,
2022-01-21 15:17:40 +00:00
OBSERVABLE_INSTANCE,
} from "../symbols/identifiers";
2021-08-17 15:52:46 +00:00
import { INopeDispatcherOptions } from "../types/nope/nopeDispatcher.interface";
2020-11-07 00:45:20 +00:00
import { IPackageDescription } from "../types/nope/nopePackage.interface";
decorate(injectable(), NopeDispatcher);
decorate(injectable(), NopeObservable);
decorate(injectable(), NopeBaseModule);
2020-11-15 19:11:25 +00:00
/**
* Generates the Default Package, containing all relevant elements of the
2020-11-15 19:11:25 +00:00
* nope-package. Provide the utilized communication layer.
*
* @export
* @param options ommunicationLayer The Layer, which should be used.
* @return {*}
2020-11-15 19:11:25 +00:00
*/
export function generateNopeBasicPackage(
options: INopeDispatcherOptions,
2021-08-17 15:52:46 +00:00
singleton = false
) {
const TYPES = {
dispatcher: DISPATCHER_INSTANCE,
observableFactory: OBSERVABLE_FACTORY,
emitterFactory: EMITTER_FACTORY,
observable: OBSERVABLE_INSTANCE,
emitter: EMITTER_INSTANCE,
communicationLayer: COMMUNICATION_LAYER,
2021-12-04 07:25:26 +00:00
dispatcherOptions: DISPATCHER_OPTIONS,
};
2020-11-15 19:11:25 +00:00
const definedPackage: IPackageDescription<typeof TYPES> = {
activationHandlers: [],
autostart: {},
defaultInstances: [],
nameOfPackage: "nopeBasicPackage",
providedClasses: [
{
description: {
name: "nopeDispatcher",
selector: TYPES.dispatcher,
2021-08-17 15:52:46 +00:00
// We want to provide in this Situation allways the same dispatcher.
// type: !singleton ? InjectableNopeDispatcher : getDispatcher(options, null, singleton),
type: getDispatcher(options, {
2022-01-21 15:17:40 +00:00
singleton,
}),
2020-12-05 01:28:33 +00:00
options: {
2021-08-17 15:52:46 +00:00
// Shouldn't be required:
// scope: singleton ? "inSingletonScope" : undefined,
// toConstant: singleton ? true : undefined
2021-12-04 07:25:26 +00:00
toConstant: true,
},
},
settings: {
2021-12-04 07:25:26 +00:00
allowInstanceGeneration: false,
},
},
{
description: {
2021-08-17 15:52:46 +00:00
name: "dispatcherOptions",
selector: TYPES.dispatcherOptions,
type: options,
options: {
2021-12-04 07:25:26 +00:00
toConstant: true,
},
},
settings: {
2021-12-04 07:25:26 +00:00
allowInstanceGeneration: false,
},
},
{
description: {
name: "nopeEmitter",
selector: TYPES.emitter,
factorySelector: TYPES.emitterFactory,
type: InjectableNopeEventEmitter,
},
settings: {
allowInstanceGeneration: false,
},
},
{
description: {
name: "nopeObservable",
selector: TYPES.observable,
factorySelector: TYPES.observableFactory,
2021-12-04 07:25:26 +00:00
type: InjectableNopeObservable,
},
settings: {
2021-12-04 07:25:26 +00:00
allowInstanceGeneration: false,
},
},
],
providedFunctions: [],
requiredPackages: [],
2021-12-04 07:25:26 +00:00
types: TYPES,
};
2020-11-07 00:45:20 +00:00
return definedPackage;
}