Class QueryState<TData>
- Namespace
- DotNetQuery.Core
- Assembly
- DotNetQuery.Core.dll
An immutable snapshot of a query's current state. Use the static factory methods to create instances.
public sealed record QueryState<TData> : IEquatable<QueryState<TData>>
Type Parameters
TDataThe type of data returned by the query.
- Inheritance
-
QueryState<TData>
- Implements
-
IEquatable<QueryState<TData>>
- Inherited Members
Properties
CurrentData
The data returned by the most recent successful fetch.
null when the query has not yet succeeded or has no data.
public TData? CurrentData { get; }
Property Value
- TData
Error
The exception from the most recent failed fetch. null when not in a failure state.
public Exception? Error { get; }
Property Value
HasData
true when CurrentData is not null.
public bool HasData { get; }
Property Value
HasError
true when Error is not null.
public bool HasError { get; }
Property Value
IsFailure
public bool IsFailure { get; }
Property Value
IsFetching
public bool IsFetching { get; }
Property Value
IsIdle
public bool IsIdle { get; }
Property Value
IsSuccess
public bool IsSuccess { get; }
Property Value
LastData
The data from the previous successful fetch, carried forward across subsequent fetches and failures. Useful for rendering stale data while a new fetch is in progress.
public TData? LastData { get; }
Property Value
- TData
Status
The current lifecycle status of the query.
public QueryStatus Status { get; }
Property Value
Methods
CreateFailure(Exception, TData?)
Creates a Failure state with the given error.
public static QueryState<TData> CreateFailure(Exception error, TData? lastData = default)
Parameters
errorExceptionThe exception thrown by the fetch.
lastDataTDataData from the previous successful fetch to carry forward.
Returns
- QueryState<TData>
CreateFetching(TData?)
Creates a Fetching state, optionally carrying forward lastData.
public static QueryState<TData> CreateFetching(TData? lastData = default)
Parameters
lastDataTDataData from the previous successful fetch to carry forward.
Returns
- QueryState<TData>
CreateIdle(TData?)
Creates an Idle state, optionally carrying forward lastData.
public static QueryState<TData> CreateIdle(TData? lastData = default)
Parameters
lastDataTDataData from the previous successful fetch to carry forward.
Returns
- QueryState<TData>
CreateSuccess(TData, TData?)
Creates a Success state with the fetched data.
public static QueryState<TData> CreateSuccess(TData currentData, TData? lastData = default)
Parameters
currentDataTDataThe data returned by the fetch.
lastDataTDataData from the previous successful fetch to carry forward.
Returns
- QueryState<TData>