From b2005002ca8a7c1f867e3ac96423576fb0cc3448 Mon Sep 17 00:00:00 2001 From: Armin Jazi Date: Thu, 16 May 2024 11:49:04 +0200 Subject: [PATCH] add window scope with webdocker as default --- package.json | 2 +- src/core/ScopeRegistry.ts | 5 +++++ src/core/initialize.ts | 3 +++ src/core/main.ts | 3 ++- src/core/types.ts | 3 +++ 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/core/ScopeRegistry.ts diff --git a/package.json b/package.json index e06f554..383de3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openreplyde/web-docker", - "version": "1.1.0", + "version": "1.2.0", "type": "module", "files": [ "dist" diff --git a/src/core/ScopeRegistry.ts b/src/core/ScopeRegistry.ts new file mode 100644 index 0000000..d3120bc --- /dev/null +++ b/src/core/ScopeRegistry.ts @@ -0,0 +1,5 @@ +export default class Scope { + constructor(private readonly scope: string) { + window[this.scope] = {}; + } +} diff --git a/src/core/initialize.ts b/src/core/initialize.ts index 50ce91a..32ba1af 100644 --- a/src/core/initialize.ts +++ b/src/core/initialize.ts @@ -5,13 +5,16 @@ import ModuleRegistry from "~/core/ModuleRegistry"; import { Config } from "~/core/Config"; import { ModuleConfigService } from "~/core/ModuleConfig"; import { RegisterEventType } from "~/core/RegisterEvent"; +import ScopeRegistry from "~/core/ScopeRegistry"; export type WebDockerOptions = { configFilePath?: string; logEvents?: boolean; + scope?: string; }; const initialize = async (options: WebDockerOptions) => { + new ScopeRegistry(options.scope ?? "webdocker"); const moduleConfigService = new ModuleConfigService(); const registry = new ModuleRegistry(options.logEvents ?? false); const remoteConfigurationService = new RemoteConfigurationService(options); diff --git a/src/core/main.ts b/src/core/main.ts index 6005483..4404d25 100644 --- a/src/core/main.ts +++ b/src/core/main.ts @@ -2,7 +2,8 @@ import initialize from "~/core/initialize"; initialize({ configFilePath: import.meta.env.VITE_CONFIG_FILE_PATH, - logEvents: import.meta.env.VITE_APP_LOG_EVENTS || false + logEvents: import.meta.env.VITE_APP_LOG_EVENTS || false, + scope: "webdocker" }) .then(() => { console.log("Web Docker initialized"); diff --git a/src/core/types.ts b/src/core/types.ts index 0b87396..10e7acf 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -1,6 +1,9 @@ import RegisterEvent, { RegisterEventType } from "~/core/RegisterEvent"; declare global { + interface Window { + [key: string]: unknown; + } interface WindowEventMap { [RegisterEventType]: RegisterEvent; }