Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass meta to fix remote runtime #17

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/elements/play-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export class PlayPreview extends LitElement {
if (props.has('remoteRuntimeOrigin'))
this.#remote = RemoteApp.new(
this.remoteRuntimeOrigin,
() => this.uploaded ?? Promise.resolve({})
() => this.uploaded ?? Promise.resolve({}),
this.#meta
)
}
}
37 changes: 24 additions & 13 deletions src/runtime/remote-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,46 @@ type UIEventHandlerNiceClient = {

export class RemoteApp implements UIApp {
/** @arg uploaded Callback to test whether remote bundle is available. */
static new(gatewayOrigin: string, uploaded: () => Promise<Empty>): RemoteApp {
static new(
gatewayOrigin: string,
uploaded: () => Promise<Empty>,
meta: Readonly<Metadata>
): RemoteApp {
const channel = createChannel(gatewayOrigin)
const customPost = createClient(CustomPostDefinition, channel)
const uiEventHandler = createClient(UIEventHandlerDefinition, channel)
return new RemoteApp(
<CustomPostNiceClient>(<unknown>customPost),
<UIEventHandlerNiceClient>(<unknown>uiEventHandler),
uploaded
uploaded,
meta
)
}

#customPost: CustomPostNiceClient
#uiEventHandler: UIEventHandlerNiceClient
#meta: Metadata
#uploaded: () => Promise<Empty>
Comment on lines 70 to 73
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ”• I think these can all be marked readonly but not new to this patch πŸ‘


constructor(
customPost: CustomPostNiceClient,
uiEventHandler: UIEventHandlerNiceClient,
uploaded: () => Promise<Empty>
uploaded: () => Promise<Empty>,
meta: Readonly<Metadata>
) {
this.#customPost = customPost
this.#uiEventHandler = uiEventHandler
this.#uploaded = uploaded
this.#meta = meta
}

#newNiceMeta(meta: Readonly<Metadata> | undefined): NiceMeta {
return new NiceMeta(
Object.entries({...this.#meta, ...meta}).map(([key, {values}]) => [
key,
values.join()
])
)
}

async HandleUIEvent(
Expand All @@ -82,7 +99,7 @@ export class RemoteApp implements UIApp {
): Promise<HandleUIEventResponse> {
await this.#uploaded()
return this.#uiEventHandler.handleUIEvent(req, {
metadata: newNiceMeta(meta)
metadata: this.#newNiceMeta(meta)
})
}

Expand All @@ -92,7 +109,7 @@ export class RemoteApp implements UIApp {
): Promise<RenderPostResponse> {
await this.#uploaded()
return this.#customPost.renderPost(req, {
metadata: newNiceMeta(meta)
metadata: this.#newNiceMeta(meta)
})
}

Expand All @@ -102,7 +119,7 @@ export class RemoteApp implements UIApp {
): Promise<UIResponse> {
await this.#uploaded()
return this.#customPost.renderPostContent(req, {
metadata: newNiceMeta(meta)
metadata: this.#newNiceMeta(meta)
})
}

Expand All @@ -112,13 +129,7 @@ export class RemoteApp implements UIApp {
): Promise<UIResponse> {
await this.#uploaded()
return this.#customPost.renderPostComposer(req, {
metadata: newNiceMeta(meta)
metadata: this.#newNiceMeta(meta)
})
}
}

function newNiceMeta(meta: Readonly<Metadata> | undefined): NiceMeta {
return new NiceMeta(
Object.entries(meta ?? {}).map(([key, {values}]) => [key, values.join()])
)
}