mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
33 lines
955 B
TypeScript
33 lines
955 B
TypeScript
/**
|
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
*/
|
|
import { getInjectable } from "@ogre-tools/injectable";
|
|
import { rootComponentInjectionToken } from "./tokens";
|
|
|
|
const rootComponentInjectable = getInjectable({
|
|
id: "root-component",
|
|
instantiate: (di) => {
|
|
const options = di.injectMany(rootComponentInjectionToken);
|
|
|
|
if (options.length === 0) {
|
|
throw new Error("No intializeApp registered");
|
|
}
|
|
|
|
const intializeApp = options.find(opt => opt.isActive);
|
|
const howManyActive = options.reduce((count, cur) => count + +cur.isActive, 0);
|
|
|
|
if (!intializeApp) {
|
|
throw new Error("No initializeApp registrations are active");
|
|
}
|
|
|
|
if (howManyActive > 1) {
|
|
throw new Error("Too many initiazlizeApp registrations are active");
|
|
}
|
|
|
|
return intializeApp.Component;
|
|
},
|
|
});
|
|
|
|
export default rootComponentInjectable;
|