Skip to content

Commit

Permalink
Make TypeScript a little less weird (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter authored Apr 19, 2024
1 parent 83beef2 commit cbcb9c5
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions wasm-demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { defaultKeymap } from "@codemirror/commands";

const RENDER_SIZE = 512;
async function setup() {
const fidget = (await import("./pkg").catch(
console.error,
)) as typeof import("./pkg");
const fidget = await import("./pkg")!;

const draw = glInit();
function setScript(text: string) {
Expand All @@ -26,7 +24,7 @@ async function setup() {
// Do some string formatting to make errors cleaner
result = error
.toString()
.replace("Rhai error: ", "Rhai error:\n")
.replace("Rhai evaluation error: ", "Rhai evaluation error:\n")
.replace(" (line ", "\n(line ")
.replace(" (expecting ", "\n(expecting ");
}
Expand All @@ -39,7 +37,7 @@ async function setup() {
}
}

var timeout: any = null;
var timeout: number | null = null;
const script = new EditorView({
doc: "hello",
extensions: [
Expand All @@ -48,10 +46,10 @@ async function setup() {
EditorView.updateListener.of((v) => {
if (v.docChanged) {
if (timeout) {
clearTimeout(timeout);
window.clearTimeout(timeout);
}
const text = v.state.doc.toString();
timeout = setTimeout(() => setScript(text), 500);
timeout = window.setTimeout(() => setScript(text), 500);
}
}),
],
Expand Down Expand Up @@ -121,9 +119,9 @@ function initPositionBuffer(gl: WebGLRenderingContext): WebGLBuffer {
}

function glInit() {
const canvas = <HTMLCanvasElement>document.querySelector("#glcanvas");
const canvas = document.querySelector<HTMLCanvasElement>("#glcanvas");
// Initialize the GL context
const gl = <WebGLRenderingContext>canvas.getContext("webgl");
const gl = canvas.getContext("webgl");

// Only continue if WebGL is available and working
if (gl === null) {
Expand Down

0 comments on commit cbcb9c5

Please sign in to comment.