miniriverpod ਦੇ ਪਿੱਛੇ ਡਿਜ਼ਾਈਨ ਸਿਧਾਂਤ।

ਇਹ ਪੈਕੇਜ ਜਾਣਬੁੱਝ ਕੇ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਨੂੰ ਸੀਮਿਤ ਕਰਦਾ ਹੈ ਤਾਂ ਜੋ ਵਿਹਾਰ ਸਪਸ਼ਟ ਰਹੇ: args ਰਾਹੀਂ provider identity, scoped injection, ਅਤੇ ਅਨੁਮਾਨਯੋਗ 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 ਨੂੰ ਸਥਿਰ ਅਤੇ ਅਪਰਿਵਰਤਨਸ਼ੀਲ ਰੱਖੋ.

ਉਦਾਹਰਨ: 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);
  }
}

// ਇੰਜੈਕਟ ਕਰੋ
ProviderScope(
  overrides: [
    ProductProvider.fallback.overrideWithValue(ProductProvider(search: 'jeans')),
  ],
  child: const App(),
);
Scope dependency wiring ਨੂੰ ਸਪਸ਼ਟ ਅਤੇ ਟੈਸਟ-ਮਿੱਤਰ ਬਣਾਈ ਰੱਖਦਾ ਹੈ।
overrideWithValue ਹਰ provider instance ਉੱਤੇ ਕੰਮ ਕਰਦਾ ਹੈ, ਜਿਸ ਵਿੱਚ args-ਅਧਾਰਿਤ instances ਵੀ ਸ਼ਾਮਲ ਹਨ।
subclass + args ਵਰਤਣ ਨਾਲ autoDispose behavior ਨਹੀਂ ਬਦਲਦਾ।

ਅਗਲੇ ਕਦਮ

ਪ੍ਰੋਵਾਈਡਰ ਅਤੇ ਪੜ੍ਹਨ

watch/read/listen ਅਤੇ AsyncProvider.future ਲਈ ਠੋਸ patterns ਵੇਖੋ.

ਪ੍ਰੋਵਾਈਡਰਾਂ ਨੂੰ ਖੋਲ੍ਹੋ

ਮਿਊਟੇਸ਼ਨਜ਼

mutation tokens, mutate, ਅਤੇ ref.invoke ਨਾਲ state updates ਲਾਗੂ ਕਰੋ.

ਮਿਊਟੇਸ਼ਨਜ਼ ਖੋਲ੍ਹੋ