-
Notifications
You must be signed in to change notification settings - Fork 90
New collection event system #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 144165e The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
db5408f
to
a4b1204
Compare
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Size Change: +958 B (+1.42%) Total Size: 68.4 kB
ℹ️ View Unchanged
|
Size Change: 0 B Total Size: 1.18 kB ℹ️ View Unchanged
|
packages/db/src/collection-events.ts
Outdated
event: T, | ||
eventPayload: AllCollectionEvents[T] | ||
) { | ||
this.listeners.get(event)?.forEach((listener) => listener(eventPayload)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a listener exception could break the loop so let's wrap the listener call in a try/catch
subscriberCount: number | ||
} | ||
|
||
export type AllCollectionEvents = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export a union: export type CollectionEvent = AllCollectionEvents[keyof AllCollectionEvents] for switch(event.type) ergonomics.
This adds a new event system for generic collection events, such as status changes or notification of the change in subscribers. It's strongly typed based on the passed in event name.
This can be used by #462 as the events to trigger subscribing/unsubscribing from Query. I also intend to use it in a refactor of the live query collection and its status triggers.
We should look to replace
.onFirstReady
with.once('status:ready', () => ...)
in a followup, and deprecate that api.