-
-
Notifications
You must be signed in to change notification settings - Fork 908
/
auto_dispose.dart
99 lines (85 loc) · 3.22 KB
/
auto_dispose.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
part of '../async_notifier.dart';
/// A [AutoDisposeAsyncNotifier] base class shared between family and non-family notifiers.
///
/// Not meant for public consumption outside of riverpod_generator
@internal
abstract class BuildlessAutoDisposeAsyncNotifier<State>
extends AsyncNotifierBase<State> {
@override
late final AutoDisposeAsyncNotifierProviderElement<AsyncNotifierBase<State>,
State> _element;
@override
void _setElement(ProviderElementBase<AsyncValue<State>> element) {
_element = element as AutoDisposeAsyncNotifierProviderElement<
AsyncNotifierBase<State>, State>;
}
@override
AutoDisposeAsyncNotifierProviderRef<State> get ref => _element;
}
/// {@macro riverpod.asyncnotifier}
abstract class AutoDisposeAsyncNotifier<State>
extends BuildlessAutoDisposeAsyncNotifier<State> {
/// {@macro riverpod.asyncnotifier.build}
@visibleForOverriding
FutureOr<State> build();
}
/// {@macro riverpod.providerrefbase}
abstract class AutoDisposeAsyncNotifierProviderRef<T>
implements AsyncNotifierProviderRef<T>, AutoDisposeRef<AsyncValue<T>> {}
/// {@macro riverpod.asyncnotifier}
typedef AutoDisposeAsyncNotifierProvider<
NotifierT extends AutoDisposeAsyncNotifier<T>, T>
= AutoDisposeAsyncNotifierProviderImpl<NotifierT, T>;
/// The implementation of [AutoDisposeAsyncNotifierProvider] but with loosened type constraints
/// that can be shared with [AsyncNotifierProvider].
///
/// This enables tests to execute on both [AutoDisposeAsyncNotifierProvider] and
/// [AsyncNotifierProvider] at the same time.
@internal
class AutoDisposeAsyncNotifierProviderImpl<
NotifierT extends AsyncNotifierBase<T>,
T> extends AsyncNotifierProviderBase<NotifierT, T> with AsyncSelector<T> {
/// {@macro riverpod.notifier}
AutoDisposeAsyncNotifierProviderImpl(
super._createNotifier, {
super.name,
super.from,
super.argument,
super.dependencies,
super.debugGetCreateSourceHash,
});
/// {@macro riverpod.family}
static const family = AutoDisposeAsyncNotifierProviderFamily.new;
@override
late final Refreshable<NotifierT> notifier = _notifier<NotifierT, T>(this);
@override
late final Refreshable<Future<T>> future = _future<T>(this);
@override
AutoDisposeAsyncNotifierProviderElement<NotifierT, T> createElement() {
return AutoDisposeAsyncNotifierProviderElement._(this);
}
@override
FutureOr<T> runNotifierBuild(AsyncNotifierBase<T> notifier) {
return (notifier as AutoDisposeAsyncNotifier<T>).build();
}
/// {@macro riverpod.overridewith}
Override overrideWithNotifier(NotifierT Function() create) {
return ProviderOverride(
origin: this,
override: AutoDisposeAsyncNotifierProviderImpl<NotifierT, T>(
create,
from: from,
argument: argument,
),
);
}
}
/// The element of [AutoDisposeAsyncNotifierProvider].
class AutoDisposeAsyncNotifierProviderElement<
NotifierT extends AsyncNotifierBase<T>,
T> extends AsyncNotifierProviderElement<NotifierT, T>
with AutoDisposeProviderElementMixin<AsyncValue<T>>
implements AutoDisposeAsyncNotifierProviderRef<T> {
/// The [ProviderElementBase] for [AsyncNotifierProvider]
AutoDisposeAsyncNotifierProviderElement._(super.provider) : super._();
}