Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
styu committed Nov 21, 2024
1 parent 039ba7d commit b260312
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
6 changes: 3 additions & 3 deletions packages/widget.client.unstable/src/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("FoundryHostEventTarget", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test"],
parameterUpdateIds: ["test"],
},
},
});
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("FoundryHostEventTarget", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test"],
parameterUpdateIds: ["test"],
},
},
});
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("FoundryHostEventTarget", () => {
events: {
myEvent: {
displayName: "My Event",
parameterIds: ["test"],
parameterUpdateIds: ["test"],
},
},
});
Expand Down
10 changes: 5 additions & 5 deletions packages/widget.client.unstable/src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export class FoundryHostEventTarget<
type: T,
callback:
| HostMessageEventListener<
Extract<HostMessage<C>, { type: T }>["payload"]
(HostMessage<C> & { type: T })["payload"]
>
| HostMessageEventListenerObject<
Extract<HostMessage<C>, { type: T }>["payload"]
(HostMessage<C> & { type: T })["payload"]
>
| null,
options?: AddEventListenerOptions | boolean,
Expand All @@ -46,10 +46,10 @@ export class FoundryHostEventTarget<
type: T,
callback:
| HostMessageEventListener<
Extract<HostMessage<C>, { type: T }>["payload"]
(HostMessage<C> & { type: T })["payload"]
>
| HostMessageEventListenerObject<
Extract<HostMessage<C>, { type: T }>["payload"]
(HostMessage<C> & { type: T })["payload"]
>
| null,
options?: EventListenerOptions | boolean,
Expand All @@ -59,7 +59,7 @@ export class FoundryHostEventTarget<

public dispatchEventMessage<T extends HostMessage<C>["type"]>(
type: T,
payload: Extract<HostMessage<C>, { type: T }>["payload"],
payload: (HostMessage<C> & { type: T })["payload"],
) {
this.dispatchEvent(
new CustomEvent<HostMessage.Payload>(type, {
Expand Down
15 changes: 3 additions & 12 deletions packages/widget.client.unstable/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@ export function serializeRequest(
id,
url: input,
method: init?.method ?? "GET",
headers: serializeHeaders(init?.headers),
headers: Object.fromEntries([
...new Headers(init?.headers ?? {}).entries(),
]),
body: body as any,
};
}

function serializeHeaders(headers: HeadersInit | undefined) {
if (headers === undefined || !(headers instanceof Headers)) {
throw new Error("Header object not found");
}
const serialized: Record<string, string> = {};
for (const key of headers.keys()) {
serialized[key] = headers.get(key)!;
}
return serialized;
}

export function deserializeResponse(
response: HostMessage.Payload._unstable_FetchResponseSuccess,
): Response {
Expand Down

0 comments on commit b260312

Please sign in to comment.