From 9977c26ab400bb08e24aaa9f39c0021625deac4c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 10:52:06 +0100 Subject: [PATCH] Type memo --- .../src/components/grid/stores/config.ts | 37 ++++++++++--------- packages/frontend-core/src/utils/memo.d.ts | 10 +++++ 2 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 packages/frontend-core/src/utils/memo.d.ts diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index a020aaa149..ee328a1c18 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -1,23 +1,26 @@ import { derivedMemo } from "../../../utils" -import { derived, Readable, Writable } from "svelte/store" -import { UIDatasource, ViewV2Type } from "@budibase/types" +import { derived, Readable } from "svelte/store" +import { + SortOrder, + UIDatasource, + UISearchFilter, + ViewV2Type, +} from "@budibase/types" import { Store as StoreContext } from "." export interface ConfigStore { - datasource: Writable - initialSortColumn: Readable - initialSortOrder: any - initialFilter: any - fixedRowHeight: Readable - schemaOverrides: Readable< - Record< - string, - { - displayName?: string - disabled?: boolean - } - > - > + datasource: Readable + initialSortColumn: Readable + initialSortOrder: Readable + initialFilter: Readable + fixedRowHeight: Readable + schemaOverrides: Readable | null> notifySuccess: (message: string) => void notifyError: (message: string) => void } @@ -30,7 +33,7 @@ export type Store = ConfigStore export const createStores = (context: PropsContext): ConfigStore => { const { props } = context - const getProp = (prop: T): ConfigStore[T] => + const getProp = (prop: T) => derivedMemo(props, ($props: ConfigStore) => $props[prop]) // Derive and memoize some props so that we can react to them in isolation diff --git a/packages/frontend-core/src/utils/memo.d.ts b/packages/frontend-core/src/utils/memo.d.ts new file mode 100644 index 0000000000..de5074f784 --- /dev/null +++ b/packages/frontend-core/src/utils/memo.d.ts @@ -0,0 +1,10 @@ +import { Readable, Writable } from "svelte/store" + +declare module "./memo" { + export function memo(value: T): Writable + + export function derivedMemo( + store: Readable, + derivation: (store: TStore) => TResult + ): TResult +}