mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 12:08: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:
@@ -1,7 +1,7 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import type { Writable } from "svelte/store";
|
||||
|
||||
import type { Editor } from "@graphite/editor";
|
||||
import type { SubscriptionsRouter } from "/src/subscriptions-router";
|
||||
|
||||
export type FullscreenStore = ReturnType<typeof createFullscreenStore>;
|
||||
|
||||
@@ -14,19 +14,19 @@ const initialState: FullscreenStoreState = {
|
||||
keyboardLocked: false,
|
||||
};
|
||||
|
||||
let editorRef: Editor | undefined = undefined;
|
||||
let subscriptionsRouter: SubscriptionsRouter | undefined = undefined;
|
||||
|
||||
// Store state persisted across HMR to maintain reactive subscriptions in the component tree
|
||||
const store: Writable<FullscreenStoreState> = import.meta.hot?.data?.store || writable<FullscreenStoreState>(initialState);
|
||||
if (import.meta.hot) import.meta.hot.data.store = store;
|
||||
const { subscribe, update } = store;
|
||||
|
||||
export function createFullscreenStore(editor: Editor) {
|
||||
export function createFullscreenStore(subscriptions: SubscriptionsRouter) {
|
||||
destroyFullscreenStore();
|
||||
|
||||
editorRef = editor;
|
||||
subscriptionsRouter = subscriptions;
|
||||
|
||||
editor.subscriptions.subscribeFrontendMessage("WindowFullscreen", () => {
|
||||
subscriptions.subscribeFrontendMessage("WindowFullscreen", () => {
|
||||
toggleFullscreen();
|
||||
});
|
||||
|
||||
@@ -34,10 +34,10 @@ export function createFullscreenStore(editor: Editor) {
|
||||
}
|
||||
|
||||
export function destroyFullscreenStore() {
|
||||
const editor = editorRef;
|
||||
if (!editor) return;
|
||||
const subscriptions = subscriptionsRouter;
|
||||
if (!subscriptions) return;
|
||||
|
||||
editor.subscriptions.unsubscribeFrontendMessage("WindowFullscreen");
|
||||
subscriptions.unsubscribeFrontendMessage("WindowFullscreen");
|
||||
}
|
||||
|
||||
export function fullscreenModeChanged() {
|
||||
|
||||
Reference in New Issue
Block a user