BloomMutation<T, P> class

Asynchronous mutation manager with automated optimistic updates, automatic rollback, and cache invalidation.

Encapsulates execution state signals (data, status, error), executes optimistic updates against BloomData query cache, rolls back automatically on error, and invalidates target query keys.

Example:

final createPost = BloomMutation<Post, Map<String, dynamic>>(
  mutateFn: (params) => api.createPost(params),
  optimisticKey: ['posts'],
  optimisticData: (params, oldPosts) => [Post.fromMap(params), ...?oldPosts],
  invalidateKeys: [['posts']],
);

await createPost.mutate({'title': 'New Article'});

Constructors

BloomMutation({required MutationFn<T, P> mutateFn, List? optimisticKey, OptimisticUpdater<T, P>? optimisticData, List<List> invalidateKeys = const [], OnMutateCallback<P>? onMutate, OnSuccessCallback<T, P>? onSuccess, OnErrorCallback<P>? onError, OnSettledCallback<T, P>? onSettled})
Creates a BloomMutation instance.

Properties

data ReadonlySignal<T?>
Reactive signal holding the latest successful result data, or null.
no setter
error ReadonlySignal<Object?>
Reactive signal holding any error thrown during execution, or null.
no setter
hashCode int
The hash code for this object.
no setterinherited
invalidateKeys List<List>
List of query cache keys to invalidate upon successful completion.
final
isError bool
Whether the mutation failed with an error.
no setter
isIdle bool
Whether the mutation is in MutationStatus.idle status.
no setter
isPending bool
Whether the mutation is actively executing in background.
no setter
isSuccess bool
Whether the mutation succeeded.
no setter
mutateFn MutationFn<T, P>
The underlying mutation execution function.
final
onError OnErrorCallback<P>?
Optional hook invoked on mutation error.
final
onMutate OnMutateCallback<P>?
Optional hook invoked before mutation execution.
final
onSettled OnSettledCallback<T, P>?
Optional hook invoked when mutation settles.
final
onSuccess OnSuccessCallback<T, P>?
Optional hook invoked on successful mutation.
final
optimisticData OptimisticUpdater<T, P>?
Optimistic data transformation callback applied before network resolution.
final
optimisticKey List?
Optional query cache key targeted for optimistic updates.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
status ReadonlySignal<MutationStatus>
Reactive signal indicating the current mutation lifecycle status.
no setter

Methods

mutate(P params) Future<T?>
Safely executes mutation with parameters params.
mutateAsync(P params) Future<T>
Executes mutation returning the resolved data T or rethrowing the caught error.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Resets mutation state signals to MutationStatus.idle and clears data and error.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited