Class: ReactiveQueryCollection<T, PK, R, H, M>
Provides a reactive, observable response for a query that returns a collection of models.
This class is used for queries that return multiple results (e.g., .fetch() or .all()), and will automatically re-fetch the collection when relevant model events occur on the event bus.
Example
ts
// Use the query builder's .reactive() method to get a ReactiveQueryCollection
const usersQuery = db.model('users').where(...)
const reactive = await usersQuery.reactive()
const response = await reactive.fetch() // returns a ReactiveQueryCollection
response.on('next', (users) => { ... })
response.on('error', (err) => { ... })
response.on('complete', () => { ... })
// ...
response.unmount()Extends
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
T extends PlainObject | - | The type of the model's data. |
PK extends StringKeyOf<T> | - | The type of the primary key field. |
R extends Record<string, RelationshipConfiguration> | - | The relationships configuration for the model. |
H extends Required<ReactiveDatabaseOptions["hooks"]> | - | - |
M extends ReactiveModel<T, PK, R> | ReactiveModel<T, PK, R> | The model instance type (defaults to ReactiveModel). |
Implements
ReactiveQueryResponseInterface<M[]>ReactiveQueryCollectionAgumentations
Properties
| Property | Type | Description | Inherited from |
|---|---|---|---|
e | EventListenerMap | The internal event listener map for the emitter. | ReactiveQueryResponseInterface.e ReactiveQueryResponse.e |
value | M[] | Returns the latest query result value. Throws if the initial query has not yet completed. Throws If the query has not yet run. | ReactiveQueryResponse.value |
Methods
off()
ts
off<K>(event: string | symbol | K, listener?:
| (...args: any[]) => void
| K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never): this;Unsubscribe from an event.
Type Parameters
| Type Parameter |
|---|
K |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | symbol | K | The event name. |
listener? | | (...args: any[]) => void | K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never | Optional. The listener function to remove. |
Returns
this
the current instance for chaining
Remarks
When no listener is provided, all listeners for the event will be removed, otherwise only the specified listener will be removed.
Implementation of
ts
ReactiveQueryResponseInterface.off;Inherited from
on()
ts
on<K>(
event: string | symbol | K,
listener:
| (...args: any[]) => void
| K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never,
ctx?: any): this;Subscribe to an event with a typed listener.
Type Parameters
| Type Parameter |
|---|
K |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | symbol | K | The event name. |
listener | | (...args: any[]) => void | K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never | The listener function. |
ctx? | any | The this context to apply to the listener when it is called |
Returns
this
the current instance for chaining
Implementation of
ts
ReactiveQueryResponseInterface.on;Inherited from
once()
ts
once<K>(
event: string | symbol | K,
listener:
| (...args: any[]) => void
| K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never,
ctx?: any): this;Subscribe to an event once with a typed listener.
Type Parameters
| Type Parameter |
|---|
K |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | symbol | K | The event name. |
listener | | (...args: any[]) => void | K extends keyof ReactiveQueryResponseEvents<T> ? Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>] extends unknown[] ? (...args: Record<keyof ReactiveQueryResponseEvents<T>, any[]>[K<K>]) => void : never : never | The listener function. |
ctx? | any | The this context to apply to the listener when it is called |
Returns
this
the current instance for chaining
Implementation of
ts
ReactiveQueryResponseInterface.once;Inherited from
unmount()
ts
unmount(): void;Returns
void