Mutation<T>

Tracks a single asynchronous write and exposes its lifecycle as bindable state, notifying its attached listener as it advances so the owning component can re-render.

public class Mutation<T> : DejaObservable

Constructors#

Mutation()#

public Mutation()

Creates a mutation that resolves its cache client from the owning component (if any).

Mutation(DejaClient)#

public Mutation(DejaClient client)

Creates a mutation bound to client, for use outside a component. Throws ArgumentNullException when client is null.

State#

Member TypeDescription
IsLoading boolTrue while the mutation is running.
IsError boolTrue when the most recent execution failed.
ErrorMessage string?The failure message of the most recent execution, when IsError is true.
Data T?The result of the most recent successful execution. Void mutation shapes leave it untouched; a failure resets it to default.

Methods#

Execute (shorthand)#

public Task Execute(Func<Task<T>> mutationFunction, Action<MutationParameters<T>>? configure = null)

Runs a mutation — the shorthand for the common case, with anything else (typically InvalidateKeys) set by the configure hook. Throws ArgumentNullException when mutationFunction is null.

Execute (cancellation-aware shorthand)#

public Task Execute(Func<CancellationToken, Task<T>> mutationFunction, Action<MutationParameters<T>>? configure = null)

Runs a cancellation-aware mutation. The token is the owning component's lifetime token, so an in-flight write is abandoned when the component is disposed:

_addTodo.Execute(token => Api.AddTodoAsync(title, token));

Execute (full form)#

public Task Execute(MutationParameters<T> parameters)

Runs the mutation described by parameters. If the effective token is already cancelled (the component is gone), returns without starting the write. On success, runs the success callbacks and then invalidates InvalidateKeys — after OnSuccess, so a callback observing the result runs before dependent queries start refetching.

Failure contract#

On failure, Data resets to default, the error state is published and the error callbacks run. An InvalidOperationException wrapping the original exception is thrown only when no error callback was supplied — wire OnError (or any other error callback) and the failure stays handled instead of escaping into the component lifecycle. Cancellation is not a failure: no error state, no callbacks (settled included).