mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-20 11:28:30 +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:
@@ -1,25 +1,25 @@
|
||||
import type { Editor } from "@graphite/editor";
|
||||
import type { SubscriptionsRouter } from "/src/subscriptions-router";
|
||||
|
||||
let editorRef: Editor | undefined = undefined;
|
||||
let subscriptionsRouter: SubscriptionsRouter | undefined = undefined;
|
||||
|
||||
export function createHyperlinkManager(editor: Editor) {
|
||||
export function createHyperlinkManager(subscriptions: SubscriptionsRouter) {
|
||||
destroyHyperlinkManager();
|
||||
|
||||
editorRef = editor;
|
||||
subscriptionsRouter = subscriptions;
|
||||
|
||||
editor.subscriptions.subscribeFrontendMessage("TriggerVisitLink", async (data) => {
|
||||
subscriptions.subscribeFrontendMessage("TriggerVisitLink", async (data) => {
|
||||
window.open(data.url, "_blank", "noopener");
|
||||
});
|
||||
}
|
||||
|
||||
export function destroyHyperlinkManager() {
|
||||
const editor = editorRef;
|
||||
if (!editor) return;
|
||||
const subscriptions = subscriptionsRouter;
|
||||
if (!subscriptions) return;
|
||||
|
||||
editor.subscriptions.unsubscribeFrontendMessage("TriggerVisitLink");
|
||||
subscriptions.unsubscribeFrontendMessage("TriggerVisitLink");
|
||||
}
|
||||
|
||||
// Self-accepting HMR: tear down the old instance and re-create with the new module's code
|
||||
import.meta.hot?.accept((newModule) => {
|
||||
if (editorRef) newModule?.createHyperlinkManager(editorRef);
|
||||
if (subscriptionsRouter) newModule?.createHyperlinkManager(subscriptionsRouter);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user