Polishing: standardize binding JS resize event (fixes non-integer AA rendering); remove "X" to delete; cleanup

This commit is contained in:
Keavon Chambers
2022-02-10 02:29:45 -08:00
parent a4d3c343a0
commit 77dc125095
10 changed files with 63 additions and 49 deletions
+13 -8
View File
@@ -6,6 +6,7 @@ import { JsMessageType } from "@/dispatcher/js-messages";
export type WasmInstance = typeof import("@/../wasm/pkg");
export type RustEditorInstance = InstanceType<WasmInstance["JsEditorHandle"]>;
// `wasmImport` starts uninitialized until `initWasm()` is called in `main.ts` before the Vue app is created
let wasmImport: WasmInstance | null = null;
export async function initWasm(): Promise<void> {
if (wasmImport !== null) return;
@@ -62,20 +63,24 @@ export function getWasmInstance(): WasmInstance {
throw new Error("Editor WASM backend was not initialized at application startup");
}
type CreateEditorStateType = { dispatcher: ReturnType<typeof createJsDispatcher>; rawWasm: WasmInstance; instance: RustEditorInstance };
type CreateEditorStateType = {
/// Allows subscribing to messages from the WASM backend
rawWasm: WasmInstance;
/// Bindings to WASM wrapper declarations (generated by wasm-bindgen)
dispatcher: ReturnType<typeof createJsDispatcher>;
/// WASM wrapper's exported functions (generated by wasm-bindgen)
instance: RustEditorInstance;
};
export function createEditorState(): CreateEditorStateType {
const dispatcher = createJsDispatcher();
const rawWasm = getWasmInstance();
const rustCallback = (messageType: JsMessageType, data: Record<string, unknown>): void => {
const dispatcher = createJsDispatcher();
const instance = new rawWasm.JsEditorHandle((messageType: JsMessageType, data: Record<string, unknown>): void => {
dispatcher.handleJsMessage(messageType, data, rawWasm, instance);
};
const instance = new rawWasm.JsEditorHandle(rustCallback);
});
return {
dispatcher,
rawWasm,
dispatcher,
instance,
};
}