Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keepAliveRiverpod shorthand #3277

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/riverpod_annotation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased patch

- Improved `@Riverpod(dependencies: [...])` documentation.
- Introduces `@keepAliveRiverpod` shorthand.

## 2.3.3 - 2023-11-27

Expand Down
15 changes: 15 additions & 0 deletions packages/riverpod_annotation/lib/src/riverpod_annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class Riverpod {
/// // By not specifying "dependencies", we are saying that this provider is never scoped
/// @riverpod
/// Foo root(RootRef ref) => Foo();
///
/// @keepAliveRiverpod
/// Foo root(RootRef ref) => Foo();
///
/// // By specifying "dependencies" (even if the list is empty),
/// // we are saying that this provider is potentially scoped
/// @Riverpod(dependencies: [])
Expand All @@ -63,6 +67,13 @@ class Riverpod {
/// // as such "dependencies" is optional
/// }
///
/// @keepAliveRiverpod
/// Object? dependent(DependentRef ref) {
/// ref.watch(rootProvider);
/// // This provider (with keepAlive set to true) does not depend on any scoped provider,
/// // as such "dependencies" is optional
/// }
///
/// @Riverpod(dependencies: [])
/// Object? dependent(DependentRef ref) {
/// ref.watch(rootProvider);
Expand Down Expand Up @@ -105,6 +116,10 @@ class Riverpod {
@Target({TargetKind.classType, TargetKind.function})
const riverpod = Riverpod();

/// {@macro riverpod_annotation.provider}
@Target({TargetKind.classType, TargetKind.function})
const keepAliveRiverpod = Riverpod(keepAlive: true);

/// An annotation used to help the linter find the user-defined element from
/// the generated provider.
///
Expand Down
Loading