Files
welshman/packages/store
2025-01-28 12:26:19 -08:00
..
2024-08-01 15:33:37 -07:00
2025-01-28 12:26:19 -08:00
2024-12-13 14:16:38 -08:00
2024-12-13 14:16:38 -08:00

@welshman/store version

Utilities for dealing with svelte stores when using welshman.

import {Repository, NAMED_PEOPLE, NAMED_TOPICS, type TrustedEvent, readUserList, List} from '@welshman/util'
import {deriveEventsMapped} from '@welshman/store'

const repository = new Repository()

// Create a svelte store that performantly maps matching events in the repository to List objects
const lists = deriveEventsMapped<PublishedUserList>(repository, {
  filters: [{kinds: [NAMED_PEOPLE, NAMED_TOPICS]}],
  eventToItem: (event: TrustedEvent) => (event.tags.length > 1 ? readUserList(event) : null),
  itemToEvent: (list: List) => list.event,
})