Write flow स्पष्ट रहन्छ।

Mutations लाई provider methods का रूपमा परिभाषित गर्नुहोस्, MutationToken बाट state monitor गर्नुहोस्, र ref.invoke(call) मार्फत execute गर्नुहोस्।

mutation का निर्माण खण्डहरू

mutation भनेको mutate(token, body, concurrency: ...) बाट फर्किने Call<R, State> हो।

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 execution लाई first-class call object बनाउँछ।

Mutation execute गर्नुहोस्

ref.invoke प्रयोग गर्नुहोस् ताकि cancellation र drop व्यवहार caller लाई देखियोस्।

दूरी (Run)

Concurrency विकल्पहरू

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

सामान्य write pattern ले AsyncData लाई optimistically update गर्छ, त्यसपछि server response सँग sync गर्छ।

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 ले पुराना callers लाई CancelledMutation फ्याँक्न सक्छ।
dropLatest ले busy हुँदा DroppedMutation फ्याँक्न सक्छ।
तपाईं temporary cancellation errors दबाउन चाहनुहुन्छ भने UI मा यिनलाई समात्नुहोस्।

अर्को कदम

Flutter API

ConsumerWidget वा ConsumerStatefulWidget प्रयोग गरेर mutation state लाई UI सँग बाँध्नुहोस्।

Flutter API खोल्नुहोस्

API Reference

invoke, mutation, mutate, र MutationState प्रकारहरू छिटो समीक्षा गर्नुहोस्।

API Reference खोल्नुहोस्