2020-11-07 00:45:20 +00:00
|
|
|
/**
|
|
|
|
* @author Martin Karkowski
|
|
|
|
* @email m.karkowski@zema.de
|
|
|
|
* @create date 2020-11-06 14:20:32
|
2021-08-17 15:52:46 +00:00
|
|
|
* @modify date 2021-08-11 19:59:47
|
2020-11-07 00:45:20 +00:00
|
|
|
* @desc [description]
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { getSingleton } from "../helpers/singletonMethod";
|
2021-08-17 15:52:46 +00:00
|
|
|
import { INopeDispatcherOptions } from "../types/nope/nopeDispatcher.interface";
|
2020-12-04 18:10:33 +00:00
|
|
|
import { generateNopeBasicPackage } from "./generateNopeBasicPackage";
|
2020-11-07 00:45:20 +00:00
|
|
|
import { NopePackageLoader } from "./nopePackageLoader";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to extract a Singleton Dispatcher
|
|
|
|
* @param options The provided options for the Dispatcher
|
|
|
|
*/
|
2021-08-17 15:52:46 +00:00
|
|
|
export function getPackageLoader(options: INopeDispatcherOptions, singleton = true) {
|
|
|
|
const create = () => {
|
2020-11-07 00:45:20 +00:00
|
|
|
// Create a loader
|
2020-11-15 19:11:25 +00:00
|
|
|
const loader = new NopePackageLoader();
|
2020-11-07 00:45:20 +00:00
|
|
|
|
|
|
|
// load the default Package:
|
2021-08-17 15:52:46 +00:00
|
|
|
loader.addPackage(generateNopeBasicPackage(options, singleton)).catch((e) => {
|
2020-11-07 00:45:20 +00:00
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
|
2020-12-04 18:10:33 +00:00
|
|
|
return loader;
|
2021-08-17 15:52:46 +00:00
|
|
|
};
|
2020-11-07 00:45:20 +00:00
|
|
|
|
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("nopeBackendPackageLoader.instance", create);
|
|
|
|
|
|
|
|
return container.instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No singleton is required =>
|
|
|
|
// create a new instance.
|
|
|
|
return create();
|
2020-12-04 18:10:33 +00:00
|
|
|
}
|