From afce6892910ec9edea039b40bfd88a231a66ef6e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 25 Jun 2024 16:39:10 +0200 Subject: [PATCH] refactor: operators doesn't need to be a store --- src/lib/components/filters/content.svelte | 4 ++-- src/lib/components/filters/store.ts | 29 ++--------------------- 2 files changed, 4 insertions(+), 29 deletions(-) diff --git a/src/lib/components/filters/content.svelte b/src/lib/components/filters/content.svelte index e29c7698b..6bd854c4c 100644 --- a/src/lib/components/filters/content.svelte +++ b/src/lib/components/filters/content.svelte @@ -24,14 +24,14 @@ $: column = $columns.find((c) => c.id === columnId) as Column; - $: operatorsForColumn = Object.entries($operators) + $: operatorsForColumn = Object.entries(operators) .filter(([, v]) => v.types.includes(column?.type)) .map(([k]) => ({ label: k, value: k })); - $: operator = operatorKey ? $operators[operatorKey] : null; + $: operator = operatorKey ? operators[operatorKey] : null; $: { columnId; operatorKey = null; diff --git a/src/lib/components/filters/store.ts b/src/lib/components/filters/store.ts index bf15ba091..af66910f1 100644 --- a/src/lib/components/filters/store.ts +++ b/src/lib/components/filters/store.ts @@ -94,7 +94,7 @@ export function addFilter( value: any, // We cast to any to not cause type errors in the input components arrayValues: string[] = [] ) { - const operator = operatorKey ? get(operators)[operatorKey] : null; + const operator = operatorKey ? operators[operatorKey] : null; const column = columns.find((c) => c.id === columnId) as Column; if (!column || !operator) return; if (column.array) { @@ -259,29 +259,4 @@ function generateDefaultOperators() { return operators; } -function createOperatorStore() { - const { subscribe, set, update } = writable>({ - ...generateDefaultOperators() - }); - - return { - subscribe, - set, - update, - reset: () => { - update(() => { - return { ...generateDefaultOperators() }; - }); - }, - setActiveOperators: (activeOperators: ValidOperators[]) => { - update((operators) => { - operatorsDefault.forEach((value, key) => { - operators[key].types = activeOperators.includes(key) ? value.types : []; - }); - return operators; - }); - } - }; -} - -export const operators = createOperatorStore(); +export const operators = generateDefaultOperators();