105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
/**
|
|
* @author Martin Karkowski
|
|
* @email m.karkowski@zema.de
|
|
* @create date 2020-11-07 17:24:34
|
|
* @modify date 2021-08-11 19:59:44
|
|
* @desc [description]
|
|
*/
|
|
|
|
import { decorate, injectable } from "inversify";
|
|
import { getDispatcher } from "../dispatcher/getDispatcher";
|
|
import { nopeDispatcher } from "../dispatcher/nopeDispatcher";
|
|
import { NopeBaseModule } from "../module/BaseModule";
|
|
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";
|
|
import { INopeDispatcherOptions } from "../types/nope/nopeDispatcher.interface";
|
|
import { IPackageDescription } from "../types/nope/nopePackage.interface";
|
|
|
|
decorate(injectable(), nopeDispatcher);
|
|
decorate(injectable(), NopeObservable);
|
|
decorate(injectable(), NopeBaseModule);
|
|
|
|
/**
|
|
* Generates the Default Package, containing all relevant elements of the
|
|
* nope-package. Provide the utilized communication layer.
|
|
*
|
|
* @export
|
|
* @param options ommunicationLayer The Layer, which should be used.
|
|
* @return {*}
|
|
*/
|
|
export function generateNopeBasicPackage(
|
|
options: INopeDispatcherOptions,
|
|
singleton = false
|
|
) {
|
|
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,
|
|
// We want to provide in this Situation allways the same dispatcher.
|
|
// type: !singleton ? InjectableNopeDispatcher : getDispatcher(options, null, singleton),
|
|
type: getDispatcher(options, null, singleton),
|
|
options: {
|
|
// Shouldn't be required:
|
|
// scope: singleton ? "inSingletonScope" : undefined,
|
|
// toConstant: singleton ? true : undefined
|
|
toConstant: true
|
|
}
|
|
},
|
|
settings: {
|
|
allowInstanceGeneration: false
|
|
}
|
|
},
|
|
{
|
|
description: {
|
|
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
|
|
};
|
|
|
|
return definedPackage;
|
|
}
|