nope/lib/loader/generateNopeBasicPackage.ts

105 lines
3.0 KiB
TypeScript
Raw Normal View History

2020-11-07 00:45:20 +00:00
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
* @create date 2020-11-07 17:24:34
2021-08-17 15:52:46 +00:00
* @modify date 2021-08-11 19:59:44
2020-11-07 00:45:20 +00:00
* @desc [description]
*/
import { decorate, injectable } from "inversify";
import { getDispatcher } from "../dispatcher/getDispatcher";
2020-11-15 19:11:25 +00:00
import { nopeDispatcher } from "../dispatcher/nopeDispatcher";
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,
OBSERVABLE_FACTORY,
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,
observable: OBSERVABLE_INSTANCE,
communicationLayer: COMMUNICATION_LAYER,
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, null, 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
toConstant: true
2020-12-05 01:28:33 +00:00
}
},
settings: {
allowInstanceGeneration: false
}
},
{
description: {
2021-08-17 15:52:46 +00:00
name: "dispatcherOptions",
selector: TYPES.dispatcherOptions,
type: options,
options: {
toConstant: true
}
},
settings: {
allowInstanceGeneration: false
}
},
{
description: {
name: "nopeObservable",
selector: TYPES.observable,
factorySelector: TYPES.observableFactory,
type: InjectableNopeObservable
},
settings: {
allowInstanceGeneration: false
}
}
],
providedFunctions: [],
requiredPackages: [],
types: TYPES
};
2020-11-07 00:45:20 +00:00
return definedPackage;
}