Table of Contents

Class QueryExtensions

Namespace
Phetch.Core
Assembly
Phetch.Core.dll

A collection of helpers to simplify working with IQuery objects.

public static class QueryExtensions
Inheritance
QueryExtensions
Inherited Members

Methods

FetchAsync<TResult>(IQuery<Unit, TResult>)

Causes this query to fetch if it has not already. This does not throw if the query fails, and instead returns the error via a QueryResult<TResult>

public static Task<QueryResult<TResult>> FetchAsync<TResult>(this IQuery<Unit, TResult> self)

Parameters

self IQuery<Unit, TResult>

Returns

Task<QueryResult<TResult>>

A QueryResult<TResult> containing the outcome of the query (data or error).

Type Parameters

TResult

Remarks

If you do not need to await the completion of the query, use Fetch<TResult>(IQuery<Unit, TResult>) instead.

This is equivalent to SetArgAsync(TArg), but for parameterless queries.

Fetch<TResult>(IQuery<Unit, TResult>)

Causes this query to fetch if it has not already. Returns immediately, without waiting for the query to complete.

public static void Fetch<TResult>(this IQuery<Unit, TResult> self)

Parameters

self IQuery<Unit, TResult>

Type Parameters

TResult

Remarks

This is equivalent to SetArg<TArg, TResult>(IQuery<TArg, TResult>, TArg), but for parameterless queries.

Refetch<TArg, TResult>(IQuery<TArg, TResult>)

Re-runs the query using the most recent argument, without waiting for the result.

public static void Refetch<TArg, TResult>(this IQuery<TArg, TResult> self)

Parameters

self IQuery<TArg, TResult>

Type Parameters

TArg
TResult

Remarks

To also return the result of the query, use RefetchAsync().

Exceptions

InvalidOperationException

Thrown if no argument has been provided to the query

SetArg<TArg, TResult>(IQuery<TArg, TResult>, TArg)

Updates the argument for this query, and re-runs the query if the argument has changed. Returns immediately, without waiting for the query to complete.

public static void SetArg<TArg, TResult>(this IQuery<TArg, TResult> self, TArg arg)

Parameters

self IQuery<TArg, TResult>
arg TArg

Type Parameters

TArg
TResult

Remarks

If you need to await the completion of the query, use SetArgAsync(TArg) instead.

TriggerAsync<TResult>(IQuery<Unit, TResult>)

Run the query function without sharing state or cache with other queries. This does not throw if the query fails, and instead returns the error via a QueryResult<TResult>

public static Task<QueryResult<TResult>> TriggerAsync<TResult>(this IQuery<Unit, TResult> self)

Parameters

self IQuery<Unit, TResult>

Returns

Task<QueryResult<TResult>>

A QueryResult<TResult> containing the outcome of the query (data or error).

Type Parameters

TResult

Remarks

If you do not need to await the completion of the query, use Trigger instead.

This is typically used for queries that have side effects (e.g., POST requests). This has the following differences from SetArgAsync(TArg):
  • This will always run the query function, even if it was previously run with the same query argument.
  • The state of this query (including the cached return value) will not be shared with other queries that use the same query argument.

TriggerAsync<TArg, TResult>(IQuery<TArg, TResult>, TArg, Action<QuerySuccessEventArgs<TArg, TResult>>?, Action<QueryFailureEventArgs<TArg>>?)

Run the query function without sharing state or cache with other queries. This does not throw if the query fails, and instead returns the error via a QueryResult<TResult>

public static Task<QueryResult<TResult>> TriggerAsync<TArg, TResult>(this IQuery<TArg, TResult> self, TArg arg, Action<QuerySuccessEventArgs<TArg, TResult>>? onSuccess = null, Action<QueryFailureEventArgs<TArg>>? onFailure = null)

Parameters

self IQuery<TArg, TResult>

The query to trigger.

arg TArg

The argument to pass to the query function

onSuccess Action<QuerySuccessEventArgs<TArg, TResult>>

An optional callback which will be fired if the query succeeds.

onFailure Action<QueryFailureEventArgs<TArg>>

An optional callback which will be fired if the query fails. This is not fired if the query is cancelled.

Returns

Task<QueryResult<TResult>>

A QueryResult<TResult> containing the outcome of the query (data or error).

Type Parameters

TArg
TResult

Remarks

If you do not need to await the completion of the query, use Trigger instead.

This is typically used for queries that have side effects (e.g., POST requests). This has the following differences from SetArgAsync(TArg):
  • This will always run the query function, even if it was previously run with the same query argument.
  • The state of this query (including the cached return value) will not be shared with other queries that use the same query argument.

Trigger<TResult>(IQuery<Unit, TResult>, Action<QuerySuccessEventArgs<Unit, TResult>>?, Action<QueryFailureEventArgs<Unit>>?)

Run the query function without sharing state or cache with other queries. Returns immediately, without waiting for the query to complete.

public static void Trigger<TResult>(this IQuery<Unit, TResult> self, Action<QuerySuccessEventArgs<Unit, TResult>>? onSuccess = null, Action<QueryFailureEventArgs<Unit>>? onFailure = null)

Parameters

self IQuery<Unit, TResult>

The query to trigger.

onSuccess Action<QuerySuccessEventArgs<Unit, TResult>>

An optional callback which will be fired if the query succeeds.

onFailure Action<QueryFailureEventArgs<Unit>>

An optional callback which will be fired if the query fails. This is not fired if the query is cancelled.

Type Parameters

TResult

Remarks

To also return the result of the query, use TriggerAsync(TArg).

This is typically used for queries that have side effects (e.g., POST requests). This has the following differences from SetArg:
  • This will always run the query function, even if it was previously run with the same query argument.
  • The state of this query (including the cached return value) will not be shared with other queries that use the same query argument.

Trigger<TArg, TResult>(IQuery<TArg, TResult>, TArg, Action<QuerySuccessEventArgs<TArg, TResult>>?, Action<QueryFailureEventArgs<TArg>>?)

Run the query function without sharing state or cache with other queries. Returns immediately, without waiting for the query to complete.

public static void Trigger<TArg, TResult>(this IQuery<TArg, TResult> self, TArg arg, Action<QuerySuccessEventArgs<TArg, TResult>>? onSuccess = null, Action<QueryFailureEventArgs<TArg>>? onFailure = null)

Parameters

self IQuery<TArg, TResult>

The query to trigger.

arg TArg

The argument to pass to the query.

onSuccess Action<QuerySuccessEventArgs<TArg, TResult>>

An optional callback which will be fired if the query succeeds.

onFailure Action<QueryFailureEventArgs<TArg>>

An optional callback which will be fired if the query fails. This is not fired if the query is cancelled.

Type Parameters

TArg
TResult

Remarks

To also return the result of the query, use TriggerAsync(TArg).

This is typically used for queries that have side effects (e.g., POST requests). This has the following differences from SetArg:
  • This will always run the query function, even if it was previously run with the same query argument.
  • The state of this query (including the cached return value) will not be shared with other queries that use the same query argument.