src/app/data-dgql/query.ts
A piece of observable data.
DataQuery is a stateful interface for interacting with an API object. Instead of calling a function to make an API request, DataQuery lets you declare the ID (like an endpoint) and request parameters (in #params) of the data you want, and will automatically load the data when needed. Data can then be accessed synchronously with the #current property.
Upon adding a subscriber with #subscribe, data will loaded from the API and stored in the cache. Subsequent viewers can then immediately access the cached data.
When done using a DataQuery subscription, it must be manually destroyed by calling
sub.unsubscribe()
on the Subscription object returned by
subscribe, as it may leak memory otherwise.
See DataNode and DataList for the two main types of data that use DataQuery.
Observable
Properties |
Methods |
Accessors |
id |
Type : I
|
Defined in src/app/data-dgql/query.ts:48
|
The ID of this data. |
interactive |
Default value : false
|
Defined in src/app/data-dgql/query.ts:137
|
If true, will prolong debounce time a bit. |
loading |
Default value : false
|
Defined in src/app/data-dgql/query.ts:49
|
dataAsPromise |
dataAsPromise()
|
Defined in src/app/data-dgql/query.ts:171
|
Returns the data as a promise, without having to create a subscription. If cached data is available, this will return the data immediately; otherwise, this will load the data with an API request. Example
Returns :
Promise<T>
|
hydrateRaw | ||||||
hydrateRaw(preparedData: Promise
|
||||||
Defined in src/app/data-dgql/query.ts:231
|
||||||
Use when data has not yet been loaded but is available from elsewhere.
Parameters :
Returns :
void
|
invalidate |
invalidate()
|
Defined in src/app/data-dgql/query.ts:264
|
Deletes current data.
Returns :
void
|
load |
load()
|
Defined in src/app/data-dgql/query.ts:222
|
Loads data.
Returns :
void
|
loadDebounced | ||||||
loadDebounced(interactive)
|
||||||
Defined in src/app/data-dgql/query.ts:250
|
||||||
Loads data after a short delay. Will debounce.
Parameters :
Returns :
void
|
loadIfNeeded |
loadIfNeeded()
|
Defined in src/app/data-dgql/query.ts:240
|
Will load data if it's stale or not present.
Returns :
void
|
subscribeLazy | ||||||||
subscribeLazy(...args: any[])
|
||||||||
Defined in src/app/data-dgql/query.ts:295
|
||||||||
Will subscribe to the data, but not cause a reload unless there is no data.
Parameters :
Returns :
Subscription
|
hasData |
gethasData()
|
Defined in src/app/data-dgql/query.ts:68
|
Returns true if data is currently available.
Returns :
boolean
|
current |
getcurrent()
|
Defined in src/app/data-dgql/query.ts:73
|
The currently loaded data.
Returns :
T
|
params | ||||||
getparams()
|
||||||
Defined in src/app/data-dgql/query.ts:86
|
||||||
Parameters that will be passed to the request. Changing this property will automatically trigger a load.
Returns :
P | undefined
|
||||||
setparams(p: P)
|
||||||
Defined in src/app/data-dgql/query.ts:89
|
||||||
Parameters :
Returns :
void
|
subscriberCount |
getsubscriberCount()
|
Defined in src/app/data-dgql/query.ts:330
|
Returns the number of subscribers for this data.
Returns :
number
|