QueryRef<T> class
abstract
final
Typed queries
A reference to one cache entry of a plain query: a definition bound to its input.
Calling a QueryFamily returns one, and a QueryDefinition is one. It is what an application passes around instead of a key and a type argument:
final device = devices.detail('d1'); // QueryRef<Device>
final observer = QueryObserver(client, device.options());
final Device fetched = await device.fetch(client);
final Device? cached = device.read(client);
device.write(client, updated);
await device.invalidate(client);
A reference is a value. It holds no client, so it can be a constant of the application and be used with any client, and making one fetches nothing, creates no cache entry and starts no timer. Two references are equal when they address the same entry with the same data type, whichever definition instance made them; the fetch function is not compared. A plain and an infinite reference are never equal.
A reference can be assigned to a wider type, QueryRef<Object?>. A
write through it of a value that is not of the real data type then
compiles, and is refused when it runs, before anything is written.
- Inheritance
-
- Object
- QueryTarget
- QueryEntryRef<
T> - QueryRef
- Implementers
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
-
key
→ TypedQueryKey<
T> -
The entry's key with its data type.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
cancel(
QueryClient client, {bool revert = true, bool silent = false}) → Future< void> -
Cancels the fetches in flight for the selected entries:
QueryClient.cancelQueries over this target. An optimistic update
calls this first, so that a response on its way cannot overwrite the
value it is about to write.
inherited
-
fetch(
QueryClient client, {bool revalidateIfStale = false}) → Future< T> - Fetches the query and completes with its data: QueryClient.query with options.
-
filters(
{QueryTypeFilter? type, bool? stale, FetchStatus? fetchStatus, QueryStatus? status, bool predicate(Query< Object?> query)?}) → QueryFilters -
The filters that select this target, for everything that takes
QueryFilters: the client's bulk operations,
QueryClient.isFetching, a cache listener.inherited -
invalidate(
QueryClient client, {RefetchType? refetchType, bool cancelRefetch = true}) → Future< void> -
Marks every selected entry stale and refetches the ones in use:
QueryClient.invalidateQueries over this target, with its parameters.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
options(
) → QueryObserverOptions< T> - The options of this query, for an observer, QueryClient.query or any other consumer of QueryObserverOptions.
-
read(
QueryClient client) → T? -
The cached data, or
nullwhen there is none. A plain read: it neither fetches nor subscribes. Throws QueryDataTypeError when the entry holds another type.inherited -
refetch(
QueryClient client, {bool cancelRefetch = true}) → Future< void> -
Refetches every selected entry that can fetch:
QueryClient.refetchQueries over this target.
inherited
-
remove(
QueryClient client) → void -
Removes every selected entry from the cache:
QueryClient.removeQueries over this target. Removing a reference's
entry is how a rollback restores "nothing was cached".
inherited
-
reset(
QueryClient client, {bool cancelRefetch = true}) → Future< void> -
Puts every selected entry back to its initial state and refetches the
ones in use: QueryClient.resetQueries over this target.
inherited
-
state(
QueryClient client) → QueryState< T> ? -
The entry's state, or
nullwhen there is no entry. ItshasDatais what tells a cachednullfrom no data.inherited -
toString(
) → String -
A string representation of this object.
override
-
update(
QueryClient client, T? updater(T? previous), {DateTime? updatedAt}) → T? -
Writes what
updaterreturns for the data cached now, and returns what the cache then holds.inherited -
write(
QueryClient client, T value, {DateTime? updatedAt}) → T -
Writes
valueinto the cache and returns what the cache then holds (after structural sharing, that may be the instance already cached).inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override