Skip to content

Commit

Permalink
Added AsyncNotifier.listenSelf
Browse files Browse the repository at this point in the history
fixes #3795
  • Loading branch information
rrousselGit committed Oct 22, 2024
1 parent 2876c7f commit 54bed92
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased 2.6.1

- Added `AsyncNotifier.listenSelf`. It was mistakenly absent from the 2.6.0 release

## 2.6.0 - 2024-10-20

- Deprecated all `Ref` subclasses. Instead, use `Ref` itself.
Expand Down
4 changes: 4 additions & 0 deletions packages/hooks_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased 2.6.1

- Added `AsyncNotifier.listenSelf`. It was mistakenly absent from the 2.6.0 release

## 2.6.0 - 2024-10-20

- Deprecated all `Ref` subclasses. Instead, use `Ref` itself.
Expand Down
4 changes: 4 additions & 0 deletions packages/riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased 2.6.1

- Added `AsyncNotifier.listenSelf`. It was mistakenly absent from the 2.6.0 release

## 2.6.0 - 2024-10-20

- Deprecated all `Ref` subclasses. Instead, use `Ref` itself.
Expand Down
9 changes: 9 additions & 0 deletions packages/riverpod/lib/src/async_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ abstract class AsyncNotifierBase<State> {

void _setElement(ProviderElementBase<AsyncValue<State>> element);

/// {@macro notifier.listen}
void listenSelf(
void Function(AsyncValue<State>? previous, AsyncValue<State> next)
listener, {
void Function(Object error, StackTrace stackTrace)? onError,
}) {
_element.listenSelf(listener, onError: onError);
}

/// The value currently exposed by this [AsyncNotifier].
///
/// Defaults to [AsyncLoading] inside the [AsyncNotifier.build] method.
Expand Down
2 changes: 2 additions & 0 deletions packages/riverpod/lib/src/notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ abstract class NotifierBase<State> {

void _setElement(ProviderElementBase<State> element);

/// {@template notifier.listen}
/// Listens to changes on the value exposed by this provider.
///
/// The listener will be called immediately after the provider completes building.
///
/// As opposed to [Ref.listen], the listener will be called even if
/// [ProviderElementBase.updateShouldNotify] returns false, meaning that the previous
/// and new value can potentially be identical.
/// {@endtemplate}
void listenSelf(
void Function(State? previous, State next) listener, {
void Function(Object error, StackTrace stackTrace)? onError,
Expand Down

0 comments on commit 54bed92

Please sign in to comment.