https://github.com/oldvis/gallery
Tip revision: 9798cde3778299d40523107bc9e33d20d60f2c98 authored by shellywhen on 24 January 2024, 07:59:25 UTC
Update README.md
Update README.md
Tip revision: 9798cde
selectors.ts
import { storeToRefs } from 'pinia'
import { SelectorType, useStore as useSelectorStore } from '~/stores/selector'
import type { Selector } from '~/stores/selector'
/** Use the selected values for the given field. */
export const useSelected = (fieldName: string): ComputedRef<Set<string>> => {
const { selectors } = storeToRefs(useSelectorStore())
const selected = computed((): Set<string> => (
new Set(selectors.value
.filter((d) => {
if (d.type !== SelectorType.Sift) return false
const query = d.query as Selector<SelectorType.Sift>['query'] as Record<string, Record<string, unknown>>
return (fieldName in query)
&& (query[fieldName] !== undefined && query[fieldName] !== null)
&& ('$eq' in query[fieldName])
})
.map((d) => (
(d.query as Record<string, Record<'$eq', string>>)[fieldName].$eq
)))
))
return selected
}
