Skip to content

Commit

Permalink
migrate(zustand): work through the type consequences of setting Store…
Browse files Browse the repository at this point in the history
…Api to null.
  • Loading branch information
crhallberg committed Jan 14, 2025
1 parent 7122963 commit 0e8cd8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -488,20 +488,23 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
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) => {
Expand Down Expand Up @@ -696,24 +699,31 @@ export default class OpenSeadragonExtension extends BaseExtension<Config> {
);
},
onClose: () => {
this.store.getState().closeDialogue();
this.closeActiveDialogue();
},
onDownloadCurrentView: (canvas: Canvas) => {
const viewer: any = this.getViewer();
window.open(<string>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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class BaseExtension<T extends BaseConfig> implements IExtension {
restrictedDialogue: RestrictedDialogue;
shell: Shell;
shifted: boolean = false;
store: StoreApi<ExtensionState>;
store: StoreApi<ExtensionState | null>; // null for dispose()
tabbing: boolean = false;
browserDetect: BrowserDetect;
locales = {};
Expand Down

0 comments on commit 0e8cd8e

Please sign in to comment.