From 3b2071432a6564d3d59b225975f7e2cb17d077ec Mon Sep 17 00:00:00 2001 From: Liam Robinson Date: Tue, 9 Jan 2024 02:16:30 +0100 Subject: [PATCH 1/3] Override AthenaClient.webview.on functions Let us override AthenaClient.webview.on functions. Just had the problem that i searched for hours why my Plugin keeps using an old value until i found out that the ClientEvents get cached. Maybe there is another better work around than this pull if yes please lmk and close it. --- src/core/client/webview/index.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/client/webview/index.ts b/src/core/client/webview/index.ts index b239dd4055..2703d424d7 100644 --- a/src/core/client/webview/index.ts +++ b/src/core/client/webview/index.ts @@ -603,12 +603,16 @@ export function ready(pageName: string, callback: AnyCallback) { * @param {(...args: any[]) => void} callback * */ -export function on(eventName: EventNames, callback: AnyCallback) { +export function on(eventName: EventNames, callback: AnyCallback, overide: boolean = false) { if (ClientEvents[String(eventName)]) { - console.warn(`[Client] Duplicate Event Name (${eventName}) for Athena.webview.on (WebViewController.onInvoke)`); - - console.warn(`Did not register duplicate event.`); - return; + if (override) { + delete ClientEvents[String(eventName)]; + } else { + console.warn(`[Client] Duplicate Event Name (${eventName}) for Athena.webview.on (WebViewController.onInvoke)`); + + console.warn(`Did not register duplicate event.`); + return; + } } ClientEvents[String(eventName)] = callback; From 77826dbfa474f89645dd58d5e81576d98dc7ccd4 Mon Sep 17 00:00:00 2001 From: Liam Robinson Date: Tue, 9 Jan 2024 02:19:17 +0100 Subject: [PATCH 2/3] fixed typo --- src/core/client/webview/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/client/webview/index.ts b/src/core/client/webview/index.ts index 2703d424d7..c3ff71a06f 100644 --- a/src/core/client/webview/index.ts +++ b/src/core/client/webview/index.ts @@ -603,7 +603,7 @@ export function ready(pageName: string, callback: AnyCallback) { * @param {(...args: any[]) => void} callback * */ -export function on(eventName: EventNames, callback: AnyCallback, overide: boolean = false) { +export function on(eventName: EventNames, callback: AnyCallback, override: boolean = false) { if (ClientEvents[String(eventName)]) { if (override) { delete ClientEvents[String(eventName)]; From 91b37da53d890dc5f7756fa99150023df86e6ff2 Mon Sep 17 00:00:00 2001 From: Liam Robinson Date: Tue, 9 Jan 2024 03:18:26 +0100 Subject: [PATCH 3/3] added .off and scraped the override idea --- src/core/client/webview/index.ts | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/client/webview/index.ts b/src/core/client/webview/index.ts index c3ff71a06f..fe483d9ae3 100644 --- a/src/core/client/webview/index.ts +++ b/src/core/client/webview/index.ts @@ -603,21 +603,33 @@ export function ready(pageName: string, callback: AnyCallback) { * @param {(...args: any[]) => void} callback * */ -export function on(eventName: EventNames, callback: AnyCallback, override: boolean = false) { +export function on(eventName: EventNames, callback: AnyCallback) { if (ClientEvents[String(eventName)]) { - if (override) { - delete ClientEvents[String(eventName)]; - } else { - console.warn(`[Client] Duplicate Event Name (${eventName}) for Athena.webview.on (WebViewController.onInvoke)`); - - console.warn(`Did not register duplicate event.`); - return; - } + console.warn(`[Client] Duplicate Event Name (${eventName}) for Athena.webview.on (WebViewController.onInvoke)`); + + console.warn(`Did not register duplicate event.`); + return; } ClientEvents[String(eventName)] = callback; } +/** + * Unregisters an event. + * + * @static + * @param {string} pageName + * @param {(...args: any[]) => void} callback + * + */ +export function off(eventName: EventNames) { + if (ClientEvents[String(eventName)]) { + delete ClientEvents[String(eventName)] + return; + } + return; +} + /** * Emit through the WebViewEvents Helper * Ensures that there is a callback event on the other side.