mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow asynchronous instances in injectable typing
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
0c0dfe5966
commit
c9503c1d14
@ -52,7 +52,7 @@ import { AppPaths } from "../common/app-paths";
|
|||||||
import { registerCustomThemes } from "./components/monaco-editor";
|
import { registerCustomThemes } from "./components/monaco-editor";
|
||||||
import { getDi } from "./components/getDi";
|
import { getDi } from "./components/getDi";
|
||||||
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
||||||
import type { IDependencyInjectionContainer } from "@ogre-tools/injectable";
|
import type { DependencyInjectionContainer } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
if (process.isMainFrame) {
|
if (process.isMainFrame) {
|
||||||
SentryInit();
|
SentryInit();
|
||||||
@ -76,7 +76,7 @@ type AppComponent = React.ComponentType & {
|
|||||||
init(rootElem: HTMLElement): Promise<void>;
|
init(rootElem: HTMLElement): Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function bootstrap(comp: () => Promise<AppComponent>, di: IDependencyInjectionContainer) {
|
export async function bootstrap(comp: () => Promise<AppComponent>, di: DependencyInjectionContainer) {
|
||||||
const rootElem = document.getElementById("app");
|
const rootElem = document.getElementById("app");
|
||||||
const logPrefix = `[BOOTSTRAP-${process.isMainFrame ? "ROOT" : "CLUSTER"}-FRAME]:`;
|
const logPrefix = `[BOOTSTRAP-${process.isMainFrame ? "ROOT" : "CLUSTER"}-FRAME]:`;
|
||||||
|
|
||||||
|
|||||||
@ -20,10 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createContainer } from "@ogre-tools/injectable";
|
import { createContainer } from "@ogre-tools/injectable";
|
||||||
import type { IConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable";
|
import type { ConfigurableDependencyInjectionContainer } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
export const getDi = () => {
|
export const getDi = () => {
|
||||||
const di: IConfigurableDependencyInjectionContainer = createContainer(
|
const di: ConfigurableDependencyInjectionContainer = createContainer(
|
||||||
() => require.context("./", true, /\.injectable\.(ts|tsx)$/),
|
() => require.context("./", true, /\.injectable\.(ts|tsx)$/),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -24,11 +24,11 @@ import { memoize } from "lodash/fp";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
createContainer,
|
createContainer,
|
||||||
IConfigurableDependencyInjectionContainer,
|
ConfigurableDependencyInjectionContainer,
|
||||||
} from "@ogre-tools/injectable";
|
} from "@ogre-tools/injectable";
|
||||||
|
|
||||||
export const getDiForUnitTesting = () => {
|
export const getDiForUnitTesting = () => {
|
||||||
const di: IConfigurableDependencyInjectionContainer = createContainer();
|
const di: ConfigurableDependencyInjectionContainer = createContainer();
|
||||||
|
|
||||||
getInjectableFilePaths()
|
getInjectableFilePaths()
|
||||||
.map(key => {
|
.map(key => {
|
||||||
|
|||||||
10
types/ogre-tools-injectable-react.d.ts
vendored
10
types/ogre-tools-injectable-react.d.ts
vendored
@ -20,16 +20,16 @@
|
|||||||
*/
|
*/
|
||||||
/// <reference types="react" />
|
/// <reference types="react" />
|
||||||
declare module "@ogre-tools/injectable-react" {
|
declare module "@ogre-tools/injectable-react" {
|
||||||
import type { IDependencyInjectionContainer, IInjectable } from "@ogre-tools/injectable";
|
import type { DependencyInjectionContainer, Injectable } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
interface IDependencyInjectionContainerProviderProps {
|
interface DependencyInjectionContainerProviderProps {
|
||||||
di: IDependencyInjectionContainer;
|
di: DependencyInjectionContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DiContextProvider: React.Provider<IDependencyInjectionContainerProviderProps>;
|
export const DiContextProvider: React.Provider<DependencyInjectionContainerProviderProps>;
|
||||||
|
|
||||||
export const Inject: <
|
export const Inject: <
|
||||||
TComponentInjectable extends IInjectable<any>,
|
TComponentInjectable extends Injectable<any>,
|
||||||
>({
|
>({
|
||||||
Component,
|
Component,
|
||||||
injectableKey,
|
injectableKey,
|
||||||
|
|||||||
33
types/ogre-tools-injectable.d.ts
vendored
33
types/ogre-tools-injectable.d.ts
vendored
@ -19,24 +19,29 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
declare module "@ogre-tools/injectable" {
|
declare module "@ogre-tools/injectable" {
|
||||||
export interface IDependencyInjectionContainer {
|
type Awaited<TMaybePromise> = TMaybePromise extends PromiseLike<infer TValue>
|
||||||
|
? TValue
|
||||||
|
: TMaybePromise;
|
||||||
|
|
||||||
|
export interface DependencyInjectionContainer {
|
||||||
inject: <
|
inject: <
|
||||||
TInjectable extends IInjectable<TInstance, TDependencies>,
|
TInjectable extends Injectable<TInstance, TDependencies>,
|
||||||
TInstance,
|
TInstance,
|
||||||
TDependencies,
|
TDependencies,
|
||||||
|
TMaybePromiseInstance = ReturnType<TInjectable["instantiate"]>,
|
||||||
>(
|
>(
|
||||||
injectableKey: TInjectable,
|
injectableKey: TInjectable,
|
||||||
) => ReturnType<TInjectable["instantiate"]>;
|
) => TMaybePromiseInstance extends PromiseLike<any>
|
||||||
|
? Awaited<TMaybePromiseInstance>
|
||||||
|
: TMaybePromiseInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IConfigurableDependencyInjectionContainer
|
export interface ConfigurableDependencyInjectionContainer
|
||||||
extends IDependencyInjectionContainer {
|
extends DependencyInjectionContainer {
|
||||||
register: (
|
register: (injectable: Injectable<any>) => void;
|
||||||
injectable: IInjectable<any> | IComponentInjectable<any>,
|
|
||||||
) => void;
|
|
||||||
preventSideEffects: () => void;
|
preventSideEffects: () => void;
|
||||||
|
|
||||||
override: <TInjectable extends IInjectable<TInstance, any>, TInstance>(
|
override: <TInjectable extends Injectable<TInstance, any>, TInstance>(
|
||||||
injectable: TInjectable,
|
injectable: TInjectable,
|
||||||
overrider:
|
overrider:
|
||||||
| ReturnType<TInjectable["instantiate"]>
|
| ReturnType<TInjectable["instantiate"]>
|
||||||
@ -47,7 +52,7 @@ declare module "@ogre-tools/injectable" {
|
|||||||
) => void;
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IInjectable<
|
export interface Injectable<
|
||||||
TInstance,
|
TInstance,
|
||||||
TDependencies extends object = {},
|
TDependencies extends object = {},
|
||||||
TInstantiationParameter extends object = {},
|
TInstantiationParameter extends object = {},
|
||||||
@ -55,7 +60,7 @@ declare module "@ogre-tools/injectable" {
|
|||||||
id?: string;
|
id?: string;
|
||||||
|
|
||||||
getDependencies: (
|
getDependencies: (
|
||||||
di?: IDependencyInjectionContainer,
|
di?: DependencyInjectionContainer,
|
||||||
) => TDependencies | Promise<TDependencies>;
|
) => TDependencies | Promise<TDependencies>;
|
||||||
|
|
||||||
lifecycle?: lifecycleEnum;
|
lifecycle?: lifecycleEnum;
|
||||||
@ -63,7 +68,9 @@ declare module "@ogre-tools/injectable" {
|
|||||||
instantiate: (
|
instantiate: (
|
||||||
dependencies: TDependencies,
|
dependencies: TDependencies,
|
||||||
instantiationParameter: TInstantiationParameter,
|
instantiationParameter: TInstantiationParameter,
|
||||||
) => TInstance;
|
) => Promise<TInstance> | TInstance;
|
||||||
|
|
||||||
|
causesSideEffects?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum lifecycleEnum {
|
export enum lifecycleEnum {
|
||||||
@ -74,5 +81,5 @@ declare module "@ogre-tools/injectable" {
|
|||||||
|
|
||||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||||
export const createContainer = (...getRequireContexts: any[]) =>
|
export const createContainer = (...getRequireContexts: any[]) =>
|
||||||
IConfigurableDependencyInjectionContainer;
|
ConfigurableDependencyInjectionContainer;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user