Skip to content

Commit 679b831

Browse files
committed
chore: try to type context as cell
1 parent ec040c6 commit 679b831

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

deno.lock

+15-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iframe-sandbox/src/common-iframe-sandbox.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { css, html, LitElement, PropertyValues } from "lit";
22
import { createRef, Ref, ref } from "lit/directives/ref.js";
33
import * as IPC from "./ipc.ts";
4-
import { getIframeContextHandler } from "./context.ts";
4+
import { type Cell, getIframeContextHandler } from "./context.ts";
55
import OuterFrame from "./outer-frame.ts";
66
import {
77
HealthCheck,
@@ -43,7 +43,7 @@ export class CommonIframeSandboxElement extends LitElement {
4343
crashed: { type: Boolean, attribute: false, state: true },
4444
};
4545
declare src: string;
46-
declare context?: object;
46+
declare context?: Cell<object>;
4747
declare crashed: boolean;
4848

4949
constructor() {
@@ -354,7 +354,7 @@ export class CommonIframeSandboxElement extends LitElement {
354354
const IframeHandler = getIframeContextHandler();
355355
if (IframeHandler != null) {
356356
for (const [_, receipt] of this.subscriptions) {
357-
IframeHandler.unsubscribe(this, this.context, receipt);
357+
IframeHandler.unsubscribe(this, this.context!, receipt);
358358
}
359359
this.subscriptions.clear();
360360
}

iframe-sandbox/src/context.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
import { TaskPerform } from "./ipc.ts";
22
import { CommonIframeSandboxElement } from "./common-iframe-sandbox.ts";
3+
import type { Cell } from "@commontools/runner";
4+
5+
export type { Cell };
36

47
// An `IframeContextHandler` is used by consumers to
58
// register how read/writing values from frames are handled.
6-
export interface IframeContextHandler {
9+
export interface IframeContextHandler<Doc extends object = object> {
710
read(element: CommonIframeSandboxElement, context: any, key: string): any;
811
write(
912
element: CommonIframeSandboxElement,
10-
context: any,
13+
context: Cell<Doc>,
1114
key: string,
1215
value: any,
1316
): void;
1417
subscribe(
1518
element: CommonIframeSandboxElement,
16-
context: any,
19+
context: Cell<Doc>,
1720
key: string,
1821
callback: (key: string, value: any) => void,
1922
doNotSendMyDataBack: boolean,
2023
): any;
2124
unsubscribe(
2225
element: CommonIframeSandboxElement,
23-
context: any,
26+
context: Cell<Doc>,
2427
receipt: any,
2528
): void;
2629
onLLMRequest(
2730
element: CommonIframeSandboxElement,
28-
context: any,
31+
context: Cell<Doc>,
2932
payload: string,
3033
): Promise<object>;
3134
onReadWebpageRequest(
3235
element: CommonIframeSandboxElement,
33-
context: any,
36+
context: Cell<Doc>,
3437
payload: string,
3538
): Promise<object>;
3639

0 commit comments

Comments
 (0)