mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 23:08:13 +08:00
Polishing: standardize binding JS resize event (fixes non-integer AA rendering); remove "X" to delete; cleanup
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user