miniriverpod පිටුපස ඇති නිර්මාණ මූලධර්ම.

මෙම පැකේජය හැසිරීම පැහැදිලිව තැබීමට විශේෂාංග සෙමින් සීමා කරයි: args මගින් provider identity, scoped injection, සහ predictable disposal semantics.

Riverpod සිට වෙනස් වන දේ

generated family classes සහ implicit notifier channels වෙනුවට, miniriverpod subclass + args + explicit invoke ට ප්‍රමුඛතාවය දේ.

ප්‍රොවයිඩර් හැඳුනුම

runtimeType + args hash

family විකල්පය

Provider / AsyncProvider subclass කර super.args((...)) යොදන්න

DI fallback

Scope<T>.required + overrideWithValue

මෙය වැදගත් වන්නේ ඇයි

සාමාන්‍ය Dart constructors භාවිතයෙන් equality සහ overrides පිළිබඳව තර්ක කළ හැක, එය debugging සහ tests සරල කරයි.

args සමඟ Provider හැඳුනුම

args provider key එක නිර්වචනය කරයි, එබැවින් එකම args කියන්නේ ProviderContainer තුළ එකම cache entry එකයි.

හැඳුනුම් නියමය

ප්‍රායෝගික ප්‍රතිවිපාක

- වෙනම family type එකක් අවශ්‍ය නැත.
- එක් එක් argument සඳහා override කිරීම provider instances සෑදීමෙන් සිදු වේ.
- අනාවැකි කළ හැකි caching සඳහා args ස්ථිර සහ immutable ලෙස තබාගන්න.

උදාහරණය: family-like provider + Scope fallback

constructor argument එකක් identity ලෙස භාවිතා කර, Scope හරහා fallback instance එකක් inject කරන්න.

class ProductProvider extends AsyncProvider<List<Product>> {
  ProductProvider({this.search = ''}) : super.args((search,));
  final String search;

  static final fallback = Scope<ProductProvider>.required('product.fallback');

  @override
  FutureOr<List<Product>> build(ref) async {
    final api = ref.watch(productsApiProvider);
    return api.search(q: search);
  }
}

// ඇතුළත් කරන්න
ProviderScope(
  overrides: [
    ProductProvider.fallback.overrideWithValue(ProductProvider(search: 'jeans')),
  ],
  child: const App(),
);
Scope dependency wiring පැහැදිලි සහ test-friendly ලෙස රඳවා තබයි.
overrideWithValue එක provider instance එකකට අනුව ක්‍රියා කරයි, args-based instances ද ඇතුළුව.
subclass + args භාවිතයෙන් autoDispose behavior වෙනස් නොවේ.

ඊළඟ පියවර

ප්‍රොවයිඩර් සහ කියවීම්

watch/read/listen සහ AsyncProvider.future සඳහා තත්‍ය patterns බලන්න.

ප්‍රොවයිඩර් විවෘත කරන්න

මුට්ටේෂන්

mutation tokens, mutate, සහ ref.invoke භාවිතයෙන් state updates ක්‍රියාත්මක කරන්න.

මුට්ටේෂන් විවෘත කරන්න