Commit a68759ce authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Migrate sidebar/store index module to TS

parent 13aae23d
import type { SidebarSettings } from '../../types/config';
import { useService } from '../service-context'; import { useService } from '../service-context';
import { createStore } from './create-store'; import { createStore } from './create-store';
import { debugMiddleware } from './debug-middleware'; import { debugMiddleware } from './debug-middleware';
...@@ -19,7 +20,7 @@ import { toastMessagesModule } from './modules/toast-messages'; ...@@ -19,7 +20,7 @@ import { toastMessagesModule } from './modules/toast-messages';
import { viewerModule } from './modules/viewer'; import { viewerModule } from './modules/viewer';
import { useStore } from './use-store'; import { useStore } from './use-store';
/** @typedef {ReturnType<createSidebarStore>} SidebarStore */ export type SidebarStore = ReturnType<typeof createSidebarStore>;
/** /**
* Create the central state store for the sidebar application. * Create the central state store for the sidebar application.
...@@ -30,15 +31,14 @@ import { useStore } from './use-store'; ...@@ -30,15 +31,14 @@ import { useStore } from './use-store';
* *
* [1] https://redux.js.org * [1] https://redux.js.org
* *
* @param {import('../../types/config').SidebarSettings} settings
* @inject * @inject
*/ */
export function createSidebarStore(settings) { export function createSidebarStore(settings: SidebarSettings) {
const middleware = [debugMiddleware]; const middleware = [debugMiddleware];
// `const` type gives `modules` a tuple type, which allows `createStore` // `const` type gives `modules` a tuple type, which allows `createStore`
// to infer properties (eg. action and selector methods) of returned store. // to infer properties (eg. action and selector methods) of returned store.
const modules = /** @type {const} */ ([ const modules = [
activityModule, activityModule,
annotationsModule, annotationsModule,
defaultsModule, defaultsModule,
...@@ -55,7 +55,7 @@ export function createSidebarStore(settings) { ...@@ -55,7 +55,7 @@ export function createSidebarStore(settings) {
sidebarPanelsModule, sidebarPanelsModule,
toastMessagesModule, toastMessagesModule,
viewerModule, viewerModule,
]); ] as const;
return createStore(modules, [settings], middleware); return createStore(modules, [settings], middleware);
} }
...@@ -67,6 +67,6 @@ export function createSidebarStore(settings) { ...@@ -67,6 +67,6 @@ export function createSidebarStore(settings) {
* {@link useStore}. * {@link useStore}.
*/ */
export function useSidebarStore() { export function useSidebarStore() {
const store = /** @type {SidebarStore} */ (useService('store')); const store = useService('store') as SidebarStore;
return useStore(store); return useStore(store);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment