Table of Contents

Class MutationState<TData, TProgress>

Namespace
Fetchling.Core
Assembly
Fetchling.Core.dll

An immutable snapshot of a progress-reporting mutation's current state. Identical to MutationState<TData> plus Progress, the latest value the mutator reported. Use the static factory methods to create instances.

public sealed record MutationState<TData, TProgress> : IEquatable<MutationState<TData, TProgress>>

Type Parameters

TData

The type of data returned by the mutation on success.

TProgress

The type of the progress values the mutator reports.

Inheritance
MutationState<TData, TProgress>
Implements
IEquatable<MutationState<TData, TProgress>>
Inherited Members

Properties

CurrentData

The data returned by the most recent successful execution. null when the mutation has not yet succeeded.

public TData? CurrentData { get; }

Property Value

TData

Error

The exception from the most recent failed execution. null when not in a failure state.

public Exception? Error { get; }

Property Value

Exception

HasData

true when the mutation has succeeded and CurrentData is available.

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

IsIdle

true when Status is Idle.

public bool IsIdle { get; }

Property Value

bool

IsRunning

true when Status is Running.

public bool IsRunning { get; }

Property Value

bool

IsSuccess

true when Status is Success.

public bool IsSuccess { get; }

Property Value

bool

Progress

The latest value the mutator reported through its IProgress<T>. default before the first report of an attempt — it resets at the start of every retry, because a retried mutator starts over. Success and Failure keep the last reported value (so a UI can show "failed at 60 %"); Idle — including after a cancellation — clears it.

public TProgress? Progress { get; }

Property Value

TProgress

Status

The current lifecycle status of the mutation.

public MutationStatus Status { get; }

Property Value

MutationStatus

Methods

CreateFailure(Exception, TProgress?)

Creates a Failure state with the given error.

public static MutationState<TData, TProgress> CreateFailure(Exception error, TProgress? progress)

Parameters

error Exception

The exception thrown by the mutation.

progress TProgress

The last progress the mutator reported before it threw.

Returns

MutationState<TData, TProgress>

CreateIdle()

Creates an Idle state with no progress.

public static MutationState<TData, TProgress> CreateIdle()

Returns

MutationState<TData, TProgress>

CreateRunning(TProgress?)

Creates a Running state carrying the latest reported progress.

public static MutationState<TData, TProgress> CreateRunning(TProgress? progress)

Parameters

progress TProgress

The latest reported progress; default before the first report.

Returns

MutationState<TData, TProgress>

CreateSuccess(TData, TProgress?)

Creates a Success state with the returned data.

public static MutationState<TData, TProgress> CreateSuccess(TData data, TProgress? progress)

Parameters

data TData

The data returned by the mutation.

progress TProgress

The last progress the mutator reported before it returned.

Returns

MutationState<TData, TProgress>