Skip to content

Commit

Permalink
refactor: useStore compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Dec 16, 2024
1 parent 55790ed commit dd86a40
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/composables/store.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isKirby5 } from "./compatibility";
import { usePanel } from "./panel";

type PanelAppStoreState = Record<string, any>;
Expand Down Expand Up @@ -25,10 +26,7 @@ interface PanelAppStore {
* @deprecated The Vuex store is removed in Kirby 5. Use the `useContent` composable instead.
*/
export function useStore() {
// `window.panel.app.$store` is not available in Kirby 5
const store = (usePanel() as any).app.$store as Readonly<PanelAppStore>;

if (!store) {
if (isKirby5()) {
return new Proxy({} as Readonly<PanelAppStore>, {
get() {
throw new Error(
Expand All @@ -38,5 +36,8 @@ export function useStore() {
});
}

// @ts-expect-error: `window.panel.app.$store` is not available in Kirby 5
const store = usePanel().app.$store as Readonly<PanelAppStore>;

return store;
}

0 comments on commit dd86a40

Please sign in to comment.