mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-24 15:28:11 +08:00
Split apart the frontend Editor type into SubscriptionsRouter and EditorHandle (#3923)
* Remove the unused Editor.raw/wasmMemory/wasmImport * Split out Editor.subscriptions * Replace editor.handle.* with editor.* (1 of 2) * Replace editor.handle.* with editor.* (2 of 2) * Replace Editor typedef with EditorHandle import * Pluralize subscription-router and rename subscriptionsRef->subscriptionsRouter and editorRef->editorHandle * Remove editor.ts * Update the readme * Fix demo art loading bug
This commit is contained in:
+26
-8
@@ -1,24 +1,42 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
|
||||
import { initWasm, createEditor } from "@graphite/editor";
|
||||
import type { Editor as GraphiteEditor } from "@graphite/editor";
|
||||
import init, { EditorHandle, receiveNativeMessage } from "@graphite/../wasm/pkg/graphite_wasm";
|
||||
import type { FrontendMessage } from "@graphite/../wasm/pkg/graphite_wasm";
|
||||
import { loadDemoArtwork } from "@graphite/utility-functions/network";
|
||||
import { operatingSystem } from "@graphite/utility-functions/platform";
|
||||
import { createSubscriptionsRouter } from "/src/subscriptions-router";
|
||||
import type { MessageName, SubscriptionsRouter } from "/src/subscriptions-router";
|
||||
|
||||
import Editor from "@graphite/components/Editor.svelte";
|
||||
|
||||
let editor: GraphiteEditor | undefined = undefined;
|
||||
let subscriptions: SubscriptionsRouter | undefined = undefined;
|
||||
let editor: EditorHandle | undefined = undefined;
|
||||
|
||||
onMount(async () => {
|
||||
await initWasm();
|
||||
// Initialize the Wasm module
|
||||
const wasm = await init();
|
||||
for (const [name, f] of Object.entries(wasm)) {
|
||||
if (name.startsWith("__node_registry")) f();
|
||||
}
|
||||
window.imageCanvases = {};
|
||||
window.receiveNativeMessage = receiveNativeMessage;
|
||||
|
||||
editor = createEditor();
|
||||
// Create the editor and subscriptions router
|
||||
const randomSeed = BigInt(Math.floor(Math.random() * Number.MAX_SAFE_INTEGER));
|
||||
subscriptions = createSubscriptionsRouter();
|
||||
editor = EditorHandle.create(operatingSystem(), randomSeed, (messageType: MessageName, messageData: FrontendMessage) => {
|
||||
subscriptions?.handleFrontendMessage(messageType, messageData);
|
||||
});
|
||||
|
||||
await loadDemoArtwork(editor);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
editor?.destroy();
|
||||
editor?.free();
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if editor !== undefined}
|
||||
<Editor {editor} />
|
||||
{#if subscriptions !== undefined && editor !== undefined}
|
||||
<Editor {subscriptions} {editor} />
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user