miniriverpod பின்னுள்ள வடிவமைப்பு கோட்பாடுகள்.

இந்த தொகுப்பு நடத்தை தெளிவாக இருக்க features ஐ நோக்கத்துடன் குறைக்கிறது: args மூலம் provider identity, scoped injection, மற்றும் முன்னறிவிக்கக்கூடிய disposal semantics.

Riverpod இலிருந்து என்ன மாறுகிறது

Generated family classes மற்றும் implicit notifier channels ஐ விட, miniriverpod subclass + args + explicit invoke ஐ விரும்புகிறது.

Provider identity

runtimeType + args hash

family மாற்று

Provider / AsyncProvider ஐ subclass செய்து super.args((...)) அனுப்பவும்

DI fallback

Scope<T>.required + overrideWithValue

இது ஏன் முக்கியம்

சாதாரண Dart constructors மூலம் equality மற்றும் overrides பற்றி reasoning செய்யலாம்; இது debugging மற்றும் tests ஐ எளிமையாக்குகிறது.

args உடன் Provider அடையாளம்

args provider key ஐ வரையறுக்கிறது, எனவே சமமான args என்பவை ProviderContainer உள்ளே ஒரே cache entry ஆகும்.

அடையாள விதி

நடைமுறை விளைவுகள்

- தனித்த family type தேவையில்லை.
- ஒவ்வொரு argument க்கும் override செய்வது provider instances உருவாக்குவதன் மூலம் செய்யப்படுகிறது.
- முன்னறிவிக்கக்கூடிய caching க்கு args நிலையானவும் immutable ஆகவும் இருக்கட்டும்.

உதாரணம்: family போன்ற 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);
  }
}

// Inject
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 க்கான தெளிவான pattern களைப் பாருங்கள்.

ப்ரொவைடர்களைத் திற

ம்யூடேஷன்கள்

mutation tokens, mutate, மற்றும் ref.invoke பயன்படுத்தி state updates ஐ செயல்படுத்தவும்.

ம்யூடேஷன்களைத் திற