From 4ee99f807c47ff442cccfddac2d784a8bccd85cb Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Thu, 2 Jan 2025 12:22:46 +0000 Subject: [PATCH] revert derivedstore implementation --- packages/builder/src/stores/builder/flags.ts | 1 + .../builder/src/stores/builder/layouts.ts | 30 +++---------------- .../builder/src/stores/builder/preview.ts | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/packages/builder/src/stores/builder/flags.ts b/packages/builder/src/stores/builder/flags.ts index 6d2150f49b..cff3ac4d12 100644 --- a/packages/builder/src/stores/builder/flags.ts +++ b/packages/builder/src/stores/builder/flags.ts @@ -1,3 +1,4 @@ +import { get } from "svelte/store" import { API } from "@/api" import { GetUserFlagsResponse } from "@budibase/types" import { BudiStore } from "../BudiStore" diff --git a/packages/builder/src/stores/builder/layouts.ts b/packages/builder/src/stores/builder/layouts.ts index 41e61e3611..af7b17fcc7 100644 --- a/packages/builder/src/stores/builder/layouts.ts +++ b/packages/builder/src/stores/builder/layouts.ts @@ -1,7 +1,7 @@ import { derived, get } from "svelte/store" import { componentStore } from "@/stores/builder" import { API } from "@/api" -import { BudiStore, DerivedBudiStore } from "../BudiStore" +import { BudiStore } from "../BudiStore" import { Layout } from "@budibase/types" interface LayoutState { @@ -9,10 +9,6 @@ interface LayoutState { selectedLayoutId: string | null } -interface DerivedLayoutState extends LayoutState { - selectedLayout: Layout | null -} - export const INITIAL_LAYOUT_STATE: LayoutState = { layouts: [], selectedLayoutId: null, @@ -79,24 +75,6 @@ export class LayoutStore extends BudiStore { export const layoutStore = new LayoutStore() -export class SelectedLayoutStore extends DerivedBudiStore< - LayoutState, - DerivedLayoutState -> { - constructor(layoutStore: LayoutStore) { - const makeDerivedStore = () => { - return derived(layoutStore, $store => { - return { - ...$store, - selectedLayout: - $store.layouts?.find( - layout => layout._id === $store.selectedLayoutId - ) || null, - } - }) - } - super(INITIAL_LAYOUT_STATE, makeDerivedStore) - } -} - -export const selectedLayout = new SelectedLayoutStore(layoutStore) +export const selectedLayout = derived(layoutStore, $store => { + return $store.layouts?.find(layout => layout._id === $store.selectedLayoutId) +}) diff --git a/packages/builder/src/stores/builder/preview.ts b/packages/builder/src/stores/builder/preview.ts index 0ec2811e15..fe14c02535 100644 --- a/packages/builder/src/stores/builder/preview.ts +++ b/packages/builder/src/stores/builder/preview.ts @@ -1,7 +1,7 @@ import { get } from "svelte/store" import { BudiStore } from "../BudiStore" -import { PreviewDevice } from "@budibase/types" +type PreviewDevice = "desktop" | "tablet" | "mobile" type PreviewEventHandler = (name: string, payload?: any) => void type ComponentContext = Record