????
Define ???? as provider methods, monitor state ?? MutationToken, ? execute through ref.invoke(call).
mutation 구성 요소
A mutation is a Call<R, State> returned ?? mutate(token, body, concurrency: ...).
Token
late final renameMut = mutation<void>(#rename)
Execution
await ref.invoke(provider.rename(...))
State
Idle / Pending / Success / Error via ref.watch(token)
참고
notifier.method() 스타일의 API와 달리 miniriverpod는 mutation 실행을 일급 call object로 다룹니다.
mutation 실행하기
Use ref.invoke so cancellation ? drop behaviors are surfaced ? the caller.
실행
동시성 옵션
concurrent : run all calls in parallel (default).
queue : FIFO; keep running queued calls even after an error.
restart : cancel previous run, keep only latest call.
dropLatest : drop incoming calls while one is running.
??: optimistic update + restart
A common write pattern updates AsyncData optimistically, then syncs ?? server response.
class UserProvider extends AsyncProvider<User?> {
UserProvider() : super.args(null);
late final renameMut = mutation<void>(#rename);
Call<void, AsyncValue<User?>> rename(String newName) => mutate(
renameMut,
(ref) async {
final cur = ref.watch(this).valueOrNull;
ref.state = AsyncData((cur ?? const User()).copyWith(name: newName), isRefreshing: true);
final api = ref.watch(apiProvider);
await api.rename(newName);
ref.state = AsyncData(await api.me());
},
concurrency: Concurrency.restart,
);
}
restart may throw CancelledMutation ? older callers.
dropLatest는 바쁜 동안 DroppedMutation을 던질 수 있습니다.
Catch these ?? UI when you want ? suppress transient cancellation errors.