refactor: operators doesn't need to be a store

This commit is contained in:
Arman
2024-06-25 16:39:10 +02:00
parent 7c0bdac7f5
commit afce689291
2 changed files with 4 additions and 29 deletions
+2 -2
View File
@@ -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;
+2 -27
View File
@@ -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<Record<string, Operator>>({
...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();