Skip to content

Commit

Permalink
Fixed a bug with the polyfill where CustomEvent wasn't inheriting fro…
Browse files Browse the repository at this point in the history
…m the right type. (#79)
  • Loading branch information
bmingles committed Oct 17, 2024
1 parent 28f4059 commit 850953e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
24 changes: 12 additions & 12 deletions packages/require-jsapi/src/polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
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<typeof Event>) {
super(...args);
}
}

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')"
Expand Down
15 changes: 10 additions & 5 deletions src/dh/dhe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export async function createInteractiveConsoleQuery(
draftQuery.updateSchedule();
}

console.log('[TESTING] schedule:', draftQuery.scheduler);

Check warning on line 178 in src/dh/dhe.ts

View workflow job for this annotation

GitHub Actions / call-unit / unit

Unexpected console statement

// type assertion gives us stronger type safety than the Promise<string>
// return type defined by the JS API types.
return dheClient.createQuery(draftQuery) as Promise<QuerySerial>;
Expand Down Expand Up @@ -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<QueryInfo>(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<QueryInfo>) => {

Check failure on line 217 in src/dh/dhe.ts

View workflow job for this annotation

GitHub Actions / call-unit / unit

'event' is defined but never used. Allowed unused args must match /^_/u
// const queryInfo = findQueryConfigForSerial(dheClient, querySerial);
if (queryInfo?.designated?.grpcUrl != null) {
resolve(queryInfo);
}
}
});
);
});

if (queryInfo.designated == null) {
Expand Down

0 comments on commit 850953e

Please sign in to comment.