From 63c103fde53b8d5305b277b1706a23672eefd478 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 29 Sep 2020 18:38:21 +0000 Subject: [PATCH] fix(core): update --- ts/smartenv.classes.smartenv.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ts/smartenv.classes.smartenv.ts b/ts/smartenv.classes.smartenv.ts index e1192c4..f8df86b 100644 --- a/ts/smartenv.classes.smartenv.ts +++ b/ts/smartenv.classes.smartenv.ts @@ -11,6 +11,21 @@ export interface IEnvObject { * Smartenv class that makes it easy */ export class Smartenv { + public async getEnvAwareModule(optionsArg: { + nodeModuleName: string; + webUrlArg: string; + getFunction: () => any; + }) { + if (this.isNode) { + const moduleResult = await this.getSafeNodeModule(optionsArg.nodeModuleName); + return moduleResult; + } else if (this.isBrowser) { + const moduleResult = await this.getSafeWebModule(optionsArg.webUrlArg, optionsArg.getFunction); + } else { + console.error('platform for loading not supported by smartenv'); + } + } + public getSafeNodeModule(moduleNameArg: string): T { if (!this.isNode) { console.error('You tried to load a node module in a wrong context'); @@ -28,7 +43,7 @@ export class Smartenv { } public loadedScripts: string[] = []; - public async getSafeWebModule(urlArg: string) { + public async getSafeWebModule(urlArg: string, getFunctionArg: () => any) { if (!this.isBrowser) { console.error('You tried to load a web module in a wrong context'); return; @@ -53,6 +68,7 @@ export class Smartenv { document.head.appendChild(script); } await done.promise; + return getFunctionArg(); } public get runtimeEnv() {