mirror of
https://github.com/pese-git/cherrypick.git
synced 2026-05-16 10:10:43 +00:00
fix(cherrypick): rename Provider typedefs to ProviderFactory
This commit is contained in:
@@ -233,7 +233,7 @@ class Binding<T> {
|
|||||||
///
|
///
|
||||||
/// Prefer this over [toProvide] when the provider is async, so the resolver
|
/// Prefer this over [toProvide] when the provider is async, so the resolver
|
||||||
/// is type-safe and avoids runtime detection overhead.
|
/// is type-safe and avoids runtime detection overhead.
|
||||||
Binding<T> toProvideAsync(AsyncProvider<T> value) {
|
Binding<T> toProvideAsync(AsyncProviderFactory<T> value) {
|
||||||
_resolver = ProviderResolver.async<T>(value);
|
_resolver = ProviderResolver.async<T>(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ class Binding<T> {
|
|||||||
///
|
///
|
||||||
/// Prefer this over [toProvideWithParams] when the provider is async, so the resolver
|
/// Prefer this over [toProvideWithParams] when the provider is async, so the resolver
|
||||||
/// is type-safe and avoids runtime detection overhead.
|
/// is type-safe and avoids runtime detection overhead.
|
||||||
Binding<T> toProvideAsyncWithParams(AsyncProviderWithParams<T> value) {
|
Binding<T> toProvideAsyncWithParams(AsyncProviderFactoryWithParams<T> value) {
|
||||||
_resolver = ProviderResolver.asyncWithParams<T>(value);
|
_resolver = ProviderResolver.asyncWithParams<T>(value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,16 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
/// Synchronous factory: `T Function()`.
|
/// Synchronous factory: `T Function()`.
|
||||||
typedef Provider<T> = T Function();
|
typedef ProviderFactory<T> = T Function();
|
||||||
|
|
||||||
/// Parameterized synchronous factory: `T Function(dynamic)`.
|
/// Parameterized synchronous factory: `T Function(dynamic)`.
|
||||||
typedef ProviderWithParams<T> = T Function(dynamic);
|
typedef ProviderFactoryWithParams<T> = T Function(dynamic);
|
||||||
|
|
||||||
/// Asynchronous factory: `Future<T> Function()`.
|
/// Asynchronous factory: `Future<T> Function()`.
|
||||||
typedef AsyncProvider<T> = Future<T> Function();
|
typedef AsyncProviderFactory<T> = Future<T> Function();
|
||||||
|
|
||||||
/// Parameterized asynchronous factory: `Future<T> Function(dynamic)`.
|
/// Parameterized asynchronous factory: `Future<T> Function(dynamic)`.
|
||||||
typedef AsyncProviderWithParams<T> = Future<T> Function(dynamic);
|
typedef AsyncProviderFactoryWithParams<T> = Future<T> Function(dynamic);
|
||||||
|
|
||||||
/// Internal interface for resolvers managed by [Binding].
|
/// Internal interface for resolvers managed by [Binding].
|
||||||
abstract class BindingResolver<T> {
|
abstract class BindingResolver<T> {
|
||||||
@@ -88,7 +88,7 @@ abstract class _BaseProviderResolver<T> implements BindingResolver<T> {
|
|||||||
|
|
||||||
/// Resolves [Binding.toProvide] with a sync `T Function()` provider.
|
/// Resolves [Binding.toProvide] with a sync `T Function()` provider.
|
||||||
class SyncProviderResolver<T> extends _BaseProviderResolver<T> {
|
class SyncProviderResolver<T> extends _BaseProviderResolver<T> {
|
||||||
final Provider<T> _provider;
|
final ProviderFactory<T> _provider;
|
||||||
Object? _cached;
|
Object? _cached;
|
||||||
bool _isCached = false;
|
bool _isCached = false;
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class SyncProviderResolver<T> extends _BaseProviderResolver<T> {
|
|||||||
|
|
||||||
/// Resolves [Binding.toProvideWithParams] with a sync `T Function(dynamic)` provider.
|
/// Resolves [Binding.toProvideWithParams] with a sync `T Function(dynamic)` provider.
|
||||||
class SyncProviderWithParamsResolver<T> extends _BaseProviderResolver<T> {
|
class SyncProviderWithParamsResolver<T> extends _BaseProviderResolver<T> {
|
||||||
final ProviderWithParams<T> _provider;
|
final ProviderFactoryWithParams<T> _provider;
|
||||||
Object? _cached;
|
Object? _cached;
|
||||||
bool _isCached = false;
|
bool _isCached = false;
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ class SyncProviderWithParamsResolver<T> extends _BaseProviderResolver<T> {
|
|||||||
|
|
||||||
/// Resolves [Binding.toProvide] with an async `Future<T> Function()` provider.
|
/// Resolves [Binding.toProvide] with an async `Future<T> Function()` provider.
|
||||||
class AsyncProviderResolver<T> extends _BaseProviderResolver<T> {
|
class AsyncProviderResolver<T> extends _BaseProviderResolver<T> {
|
||||||
final AsyncProvider<T> _provider;
|
final AsyncProviderFactory<T> _provider;
|
||||||
Future<T>? _cache;
|
Future<T>? _cache;
|
||||||
bool _isCached = false;
|
bool _isCached = false;
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ class AsyncProviderResolver<T> extends _BaseProviderResolver<T> {
|
|||||||
|
|
||||||
/// Resolves [Binding.toProvideWithParams] with an async `Future<T> Function(dynamic)` provider.
|
/// Resolves [Binding.toProvideWithParams] with an async `Future<T> Function(dynamic)` provider.
|
||||||
class AsyncProviderWithParamsResolver<T> extends _BaseProviderResolver<T> {
|
class AsyncProviderWithParamsResolver<T> extends _BaseProviderResolver<T> {
|
||||||
final AsyncProviderWithParams<T> _provider;
|
final AsyncProviderFactoryWithParams<T> _provider;
|
||||||
Future<T>? _cache;
|
Future<T>? _cache;
|
||||||
bool _isCached = false;
|
bool _isCached = false;
|
||||||
|
|
||||||
@@ -342,23 +342,24 @@ class ProviderResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Explicit sync resolver without parameters.
|
/// Explicit sync resolver without parameters.
|
||||||
static BindingResolver<T> sync<T>(Provider<T> provider) {
|
static BindingResolver<T> sync<T>(ProviderFactory<T> provider) {
|
||||||
return SyncProviderResolver<T>(provider);
|
return SyncProviderResolver<T>(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Explicit sync resolver with parameters.
|
/// Explicit sync resolver with parameters.
|
||||||
static BindingResolver<T> syncWithParams<T>(ProviderWithParams<T> provider) {
|
static BindingResolver<T> syncWithParams<T>(
|
||||||
|
ProviderFactoryWithParams<T> provider) {
|
||||||
return SyncProviderWithParamsResolver<T>(provider);
|
return SyncProviderWithParamsResolver<T>(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Explicit async resolver without parameters.
|
/// Explicit async resolver without parameters.
|
||||||
static BindingResolver<T> async<T>(AsyncProvider<T> provider) {
|
static BindingResolver<T> async<T>(AsyncProviderFactory<T> provider) {
|
||||||
return AsyncProviderResolver<T>(provider);
|
return AsyncProviderResolver<T>(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Explicit async resolver with parameters.
|
/// Explicit async resolver with parameters.
|
||||||
static BindingResolver<T> asyncWithParams<T>(
|
static BindingResolver<T> asyncWithParams<T>(
|
||||||
AsyncProviderWithParams<T> provider) {
|
AsyncProviderFactoryWithParams<T> provider) {
|
||||||
return AsyncProviderWithParamsResolver<T>(provider);
|
return AsyncProviderWithParamsResolver<T>(provider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import 'package:cherrypick/src/binding_resolver.dart';
|
|||||||
import 'package:cherrypick/src/module.dart';
|
import 'package:cherrypick/src/module.dart';
|
||||||
import 'package:cherrypick/src/observer.dart';
|
import 'package:cherrypick/src/observer.dart';
|
||||||
|
|
||||||
|
|
||||||
/// Represents a DI scope (container) for modules, subscopes,
|
/// Represents a DI scope (container) for modules, subscopes,
|
||||||
/// and dependency resolution (sync/async) in CherryPick.
|
/// and dependency resolution (sync/async) in CherryPick.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user