Skip to content

Commit 02b0854

Browse files
committed
added lib/preview-frame-interface.ts. Fixes #44.
1 parent 1ff49dd commit 02b0854

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

lib/preview-frame-interface.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This needs to be kept in its own file because we want to be able to
2+
// import it from different source bundles without having to actually
3+
// bring in any implementation.
4+
5+
// An alternative would be to use a .d.ts file for this, but we'd like
6+
// to be explicit about importing these interfaces so that the source
7+
// code is easier to understand.
8+
9+
export interface PreviewFrameErrorReporter {
10+
(message: string, line?: number): any
11+
}
12+
13+
// Eventually we might want the preview frame to exist on a separate
14+
// origin for security, which means that we'd have to use postMessage()
15+
// to communicate with it. Thus this interface needs to be asynchronous.
16+
export interface PreviewFrame extends Window {
17+
startSketch: (sketch: string, p5version: string, maxRunTime: number,
18+
loopCheckFuncName: string, baseURL: string,
19+
errorCb: PreviewFrameErrorReporter) => void
20+
}

lib/preview-frame.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { PreviewFrame,
2+
PreviewFrameErrorReporter } from "./preview-frame-interface";
3+
14
require("../css/preview-frame.css");
25

36
interface PreviewFrameWindow extends PreviewFrame {

lib/preview.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import falafel from "./falafel";
44
import LoopInserter from "./loop-inserter";
55
import makeImplicitSketch from "./implicit-sketch";
66
import PureComponent from "./pure-component";
7+
import { PreviewFrame,
8+
PreviewFrameErrorReporter } from "./preview-frame-interface";
79

810
const LOOP_CHECK_FUNC_NAME = '__loopCheck';
911

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lib/autosaver.ts",
2121
"lib/p5-widget.ts",
2222
"lib/preview-frame.ts",
23+
"lib/preview-frame-interface.ts",
2324
"lib/falafel.ts",
2425
"lib/implicit-sketch.ts",
2526
"lib/loop-inserter.ts",

typings/custom.d.ts

-13
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,3 @@ declare namespace Url {
1111
declare module "url" {
1212
export = Url;
1313
}
14-
15-
declare interface PreviewFrameErrorReporter {
16-
(message: string, line?: number): any
17-
}
18-
19-
// Eventually we might want the preview frame to exist on a separate
20-
// origin for security, which means that we'd have to use postMessage()
21-
// to communicate with it. Thus this interface needs to be asynchronous.
22-
declare interface PreviewFrame extends Window {
23-
startSketch: (sketch: string, p5version: string, maxRunTime: number,
24-
loopCheckFuncName: string, baseURL: string,
25-
errorCb: PreviewFrameErrorReporter) => void
26-
}

0 commit comments

Comments
 (0)