Table of Contents

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

TData

The type of data returned by the query.

Inheritance
QueryState<TData>
Implements
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

Exception

HasData

true when CurrentData is not null.

public bool HasData { get; }

Property Value

bool

HasError

true when Error is not null.

public bool HasError { get; }

Property Value

bool

IsFailure

true when Status is Failure.

public bool IsFailure { get; }

Property Value

bool

IsFetching

true when Status is Fetching.

public bool IsFetching { get; }

Property Value

bool

IsIdle

true when Status is Idle.

public bool IsIdle { get; }

Property Value

bool

IsSuccess

true when Status is Success.

public bool IsSuccess { get; }

Property Value

bool

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

QueryStatus

Methods

CreateFailure(Exception, TData?)

Creates a Failure state with the given error.

public static QueryState<TData> CreateFailure(Exception error, TData? lastData = default)

Parameters

error Exception

The exception thrown by the fetch.

lastData TData

Data 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

lastData TData

Data 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

lastData TData

Data 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

currentData TData

The data returned by the fetch.

lastData TData

Data from the previous successful fetch to carry forward.

Returns

QueryState<TData>