From 850953ee7386464ee53e3b668258ba2a85be7e3f Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Thu, 17 Oct 2024 11:31:38 -0500 Subject: [PATCH] Fixed a bug with the polyfill where CustomEvent wasn't inheriting from the right type. (#79) --- packages/require-jsapi/src/polyfill.ts | 24 ++++++++++++------------ src/dh/dhe.ts | 15 ++++++++++----- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/require-jsapi/src/polyfill.ts b/packages/require-jsapi/src/polyfill.ts index 6f4e22e3..2a0a1786 100644 --- a/packages/require-jsapi/src/polyfill.ts +++ b/packages/require-jsapi/src/polyfill.ts @@ -1,5 +1,17 @@ import ws from 'ws'; +class Event { + type: string; + detail: unknown; + + constructor(type: string, dict: { detail: unknown }) { + this.type = type; + if (dict) { + this.detail = dict.detail; + } + } +} + export class CustomEvent extends Event { constructor(...args: ConstructorParameters) { super(...args); @@ -7,18 +19,6 @@ export class CustomEvent extends Event { } export function polyfillDh(): void { - class Event { - type: string; - detail: unknown; - - constructor(type: string, dict: { detail: unknown }) { - this.type = type; - if (dict) { - this.detail = dict.detail; - } - } - } - // Copilot will look for `window.document.currentScript` if it finds `window`. // Since we are polyfilling `window` below, we also need to set `document` to // avoid a "Cannot read properties of undefined (reading 'currentScript')" diff --git a/src/dh/dhe.ts b/src/dh/dhe.ts index 527110d4..0859df7b 100644 --- a/src/dh/dhe.ts +++ b/src/dh/dhe.ts @@ -175,6 +175,8 @@ export async function createInteractiveConsoleQuery( draftQuery.updateSchedule(); } + console.log('[TESTING] schedule:', draftQuery.scheduler); + // type assertion gives us stronger type safety than the Promise // return type defined by the JS API types. return dheClient.createQuery(draftQuery) as Promise; @@ -210,12 +212,15 @@ export async function getWorkerInfoFromQuery( // This Promise will respond to config update events and resolve when the worker // is ready. const queryInfo = await new Promise(resolve => { - dheClient.addEventListener(dhe.Client.EVENT_CONFIG_UPDATED, _event => { - const queryInfo = findQueryConfigForSerial(dheClient, querySerial); - if (queryInfo?.designated?.grpcUrl != null) { - resolve(queryInfo); + dheClient.addEventListener( + dhe.Client.EVENT_CONFIG_UPDATED, + (event: CustomEvent) => { + // const queryInfo = findQueryConfigForSerial(dheClient, querySerial); + if (queryInfo?.designated?.grpcUrl != null) { + resolve(queryInfo); + } } - }); + ); }); if (queryInfo.designated == null) {