chore(createFilter): change format

This commit is contained in:
Ilia Mashkov
2026-01-16 17:45:11 +03:00
parent 4dbf91f600
commit f02b19eff5

View File

@@ -37,41 +37,43 @@ export function createFilter<TValue extends string>(initialState: FilterModel<TV
})),
);
// Helper to find a property by ID
const findProp = (id: string) => properties.find(p => p.id === id);
return {
get properties() {
return properties;
},
get selectedProperties() {
return properties.filter(p => p.selected);
},
get selectedCount() {
return this.selectedProperties.length;
return properties.filter(p => p.selected)?.length;
},
// 3. Methods mutate the reactive state directly
toggleProperty(id: string) {
const prop = properties.find(p => p.id === id);
if (prop) prop.selected = !prop.selected;
const property = findProp(id);
if (property) {
property.selected = !property.selected;
}
},
selectProperty(id: string) {
const prop = properties.find(p => p.id === id);
if (prop) prop.selected = true;
const property = findProp(id);
if (property) {
property.selected = true;
}
},
deselectProperty(id: string) {
const prop = properties.find(p => p.id === id);
if (prop) prop.selected = false;
const property = findProp(id);
if (property) {
property.selected = false;
}
},
selectAll() {
properties.forEach(p => p.selected = true);
properties.forEach(property => property.selected = true);
},
deselectAll() {
properties.forEach(p => p.selected = false);
properties.forEach(property => property.selected = false);
},
};
}