2020-11-06 08:10:30 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-11-06 08:52:48
|
2021-08-17 15:52:46 +00:00
|
|
|
* @modify date 2021-08-11 19:59:57
|
2020-11-06 08:10:30 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
2020-08-30 08:25:53 +00:00
|
|
|
import { getSingleton } from "../helpers/singletonMethod";
|
2020-11-07 00:45:20 +00:00
|
|
|
import { NopeGenericModule } from "../module/GenericModule";
|
2020-10-15 09:38:59 +00:00
|
|
|
import { NopeObservable } from "../observables/nopeObservable";
|
2021-09-03 05:42:37 +00:00
|
|
|
import {
|
|
|
|
INopeDispatcher,
|
|
|
|
INopeDispatcherOptions
|
|
|
|
} from "../types/nope/nopeDispatcher.interface";
|
2020-09-28 16:38:35 +00:00
|
|
|
import { nopeDispatcher } from "./nopeDispatcher";
|
2020-08-30 08:25:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to extract a Singleton Dispatcher
|
2020-09-12 00:59:30 +00:00
|
|
|
* @param options The provided options for the Dispatcher
|
2020-08-30 08:25:53 +00:00
|
|
|
*/
|
2021-09-03 05:42:37 +00:00
|
|
|
export function getDispatcher(
|
|
|
|
options: INopeDispatcherOptions,
|
|
|
|
constructorClass = null,
|
|
|
|
singleton = true
|
|
|
|
): INopeDispatcher {
|
2021-08-17 15:52:46 +00:00
|
|
|
if (constructorClass === null || constructorClass === undefined) {
|
|
|
|
constructorClass = nopeDispatcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
const create = () => {
|
2021-09-03 05:42:37 +00:00
|
|
|
const dispatcher = new constructorClass(
|
|
|
|
options,
|
|
|
|
() => new NopeObservable()
|
|
|
|
);
|
2020-11-07 00:45:20 +00:00
|
|
|
|
|
|
|
// Register a default instance generator:
|
|
|
|
// Defaultly generate a NopeGenericModule
|
2020-12-04 18:10:33 +00:00
|
|
|
dispatcher.registerInternalInstanceGenerator(
|
|
|
|
"*",
|
|
|
|
async (dispather, description) => {
|
|
|
|
const mod = new NopeGenericModule(
|
|
|
|
dispather,
|
|
|
|
() => new NopeObservable()
|
|
|
|
);
|
|
|
|
await mod.fromDescription(description, "overwrite");
|
|
|
|
// await mod.init();
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
);
|
2020-11-07 00:45:20 +00:00
|
|
|
|
|
|
|
// Return the Dispathcer
|
2020-11-11 16:08:11 +00:00
|
|
|
return dispatcher as INopeDispatcher;
|
2021-08-17 15:52:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (singleton) {
|
|
|
|
// Create a singaleton if required.
|
|
|
|
// use the container to receive the
|
|
|
|
// singleton object
|
|
|
|
const container = getSingleton("nopeBackendDispatcher.instance", create);
|
|
|
|
|
|
|
|
return container.instance;
|
|
|
|
}
|
|
|
|
|
2021-09-03 05:42:37 +00:00
|
|
|
// No singleton is required =>
|
2021-08-17 15:52:46 +00:00
|
|
|
// create a new instance.
|
|
|
|
return create();
|
2020-12-04 18:10:33 +00:00
|
|
|
}
|