From 0e8cd8e71be09f78a55f420c3a21b537622bfa65 Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Tue, 14 Jan 2025 13:42:25 -0500 Subject: [PATCH] migrate(zustand): work through the type consequences of setting StoreApi to null. --- .../uv-openseadragon-extension/Extension.ts | 24 +++++++++++++------ .../modules/uv-shared-module/BaseExtension.ts | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts index eee4845fc..021e6f5ba 100644 --- a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts +++ b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/Extension.ts @@ -488,20 +488,23 @@ export default class OpenSeadragonExtension extends BaseExtension { this.extensionHost.subscribe( IIIFEvents.SHOW_DOWNLOAD_DIALOGUE, (triggerButton) => { - this.store.getState().openDownloadDialogue(triggerButton[0]); + const state = this.store.getState(); + if (state !== null) { + state.openDownloadDialogue(triggerButton[0]); + } } ); this.extensionHost.subscribe(IIIFEvents.HIDE_DOWNLOAD_DIALOGUE, () => { - this.store.getState().closeDialogue(); + this.closeActiveDialogue(); }); this.extensionHost.subscribe(IIIFEvents.CLOSE_ACTIVE_DIALOGUE, () => { - this.store.getState().closeDialogue(); + this.closeActiveDialogue(); }); this.extensionHost.subscribe(IIIFEvents.ESCAPE, () => { - this.store.getState().closeDialogue(); + this.closeActiveDialogue(); }); // this.component.subscribe(Events.VIEW_PAGE, (e: any, index: number) => { @@ -696,24 +699,31 @@ export default class OpenSeadragonExtension extends BaseExtension { ); }, onClose: () => { - this.store.getState().closeDialogue(); + this.closeActiveDialogue(); }, onDownloadCurrentView: (canvas: Canvas) => { const viewer: any = this.getViewer(); window.open(this.getCroppedImageUri(canvas, viewer)); }, onDownloadSelection: () => { - this.store.getState().closeDialogue(); + this.closeActiveDialogue(); this.extensionHost.publish(IIIFEvents.SHOW_MULTISELECT_DIALOGUE); }, onShowTermsOfUse: () => { - this.store.getState().closeDialogue(); + this.closeActiveDialogue(); this.extensionHost.publish(IIIFEvents.SHOW_TERMS_OF_USE); }, }) ); } + closeActiveDialogue(): void { + const state = this.store.getState(); + if (state !== null) { + state.closeDialogue(); + } + } + checkForTarget(): void { if (this.data.target) { // Split target into canvas id and selector diff --git a/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts b/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts index adeac1f25..c6e278c49 100644 --- a/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts +++ b/src/content-handlers/iiif/modules/uv-shared-module/BaseExtension.ts @@ -75,7 +75,7 @@ export class BaseExtension implements IExtension { restrictedDialogue: RestrictedDialogue; shell: Shell; shifted: boolean = false; - store: StoreApi; + store: StoreApi; // null for dispose() tabbing: boolean = false; browserDetect: BrowserDetect; locales = {};