Table of Contents

Class QueryOptions

Namespace
Phetch.Core
Assembly
Phetch.Core.dll

A re-usable version of QueryOptions<TArg, TResult> without type arguments, which can be used to share query settings across multiple calls to endpoint.Use(options).

public sealed record QueryOptions : IEquatable<QueryOptions>
Inheritance
QueryOptions
Implements
Inherited Members

Constructors

QueryOptions()

A re-usable version of QueryOptions<TArg, TResult> without type arguments, which can be used to share query settings across multiple calls to endpoint.Use(options).

public QueryOptions()

Properties

Default

An instance of QueryOptions<TArg, TResult> with default values.

public static QueryOptions Default { get; }

Property Value

QueryOptions

OnDataChanged

A function that gets run when this query's data changes. Unlike OnSuccess, this is called if the query result is already cached.

public Action? OnDataChanged { get; init; }

Property Value

Action

Remarks

Like OnSuccess, this is only called if the query is currently being observed.

OnFailure

A function that gets run when this query fails.

public Action<QueryFailureEventArgs>? OnFailure { get; init; }

Property Value

Action<QueryFailureEventArgs>

Remarks

This is only called when the query is currently being observed, which means:

  1. If a query arg is changed while it is still fetching a previous arg, OnFailure will only be called for the latest arg.
  2. If the observing component is unmounted before the query finishes, OnFailure will not be called.
If you want to call a function every time a query fails, use OnFailure when creating an endpoint.

OnSuccess

A function that gets run when this query succeeds, including if the result was already cached. If the cached result is stale, this will not be called until the new result is fetched.

public Action<EventArgs>? OnSuccess { get; init; }

Property Value

Action<EventArgs>

Remarks

This is only called when the query is currently being observed, which means:

If you want to call a function every time a query succeeds (e.g., for invalidating a cache), use OnSuccess when creating an endpoint.

This is also not called if the query is already cached and the cached data is used instead. If you want to call a function every time the query data changes, use OnDataChanged.

RefetchInterval

If not null, the query will be automatically re-fetched at this interval.

public TimeSpan? RefetchInterval { get; init; }

Property Value

TimeSpan?

Remarks

Automatic re-fetches will use the RetryHandler defined on the endpoint, not the one for this query.

If a query is used in multiple components with RefetchInterval enabled and the same Arg, the query will be re-fetched at the shortest interval.

RetryHandler

If set, overrides the default RetryHandler for the endpoint.

To remove the endpoint's retry handler if it has one, set this to None.
public IRetryHandler? RetryHandler { get; init; }

Property Value

IRetryHandler

StaleTime

The amount of time until this query is considered "stale". If not set, the DefaultStaleTime (zero by default) will be used instead.

If a cached query is used before it becomes stale, the component will receive the cached result and won't re-fetch the data. If a cached query is used after it becomes stale, the cached data will be used initially, but new data will be re-fetched in the background automatically.

When set to MaxValue, queries will never be considered stale (unless they are manually invalidated).
public TimeSpan? StaleTime { get; init; }

Property Value

TimeSpan?