Skip to content

Commit

Permalink
feat: Add a way to rename family providers (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
K9i-0 committed Mar 7, 2023
1 parent 622f592 commit d659ed5
Show file tree
Hide file tree
Showing 10 changed files with 700 additions and 10 deletions.
8 changes: 5 additions & 3 deletions packages/riverpod_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Unreleased patch
## Unreleased minor

Deprecate the (new) shorthand syntax for scoping provider using the `external`
keyword. That syntax unfortunately does not work on web and therefore will be removed.
- Added support for configuring the name of providers with parameters ("families") (thanks to @K9i-0)

- Deprecate the (new) shorthand syntax for scoping provider using the `external`
keyword. That syntax unfortunately does not work on web and therefore will be removed.

## 2.0.0

Expand Down
4 changes: 4 additions & 0 deletions packages/riverpod_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ targets:
# Could be changed to "Pod", such that riverpod_generator
# would generate "countPod" instead of "countProvider"
provider_name_suffix: "Provider" # (default)
# Similar to provider_name_sufix, this is an option for renaming
# providers with parameters ("families").
# This takes precedence over provider_name_suffix.
provider_family_name_suffix: "Provider" # (default)
```

[family]: https://riverpod.dev/docs/concepts/modifiers/family
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ targets:
builders:
riverpod_generator:
options:
provider_name_suffix: 'Pod'
provider_name_suffix: 'Pod'
provider_family_name_suffix: 'ProviderFamily'
52 changes: 52 additions & 0 deletions packages/riverpod_generator/integration/build_yaml/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ FutureOr<int> countFuture(CountFutureRef ref) {
return 1;
}

@riverpod
Stream<int> countStream(CountStreamRef ref) {
return Stream.value(1);
}

@riverpod
class CountNotifier extends _$CountNotifier {
@override
Expand All @@ -27,3 +32,50 @@ class CountAsyncNotifier extends _$CountAsyncNotifier {
return 1;
}
}

@riverpod
class CountStreamNotifier extends _$CountStreamNotifier {
@override
Stream<int> build() {
return Stream.value(1);
}
}

@riverpod
int count2(Count2Ref ref, int a) {
return 1;
}

@riverpod
FutureOr<int> countFuture2(CountFuture2Ref ref, int a) {
return 1;
}

@riverpod
Stream<int> countStream2(CountStream2Ref ref, int a) {
return Stream.value(1);
}

@riverpod
class CountNotifier2 extends _$CountNotifier2 {
@override
int build(int a) {
return 1;
}
}

@riverpod
class CountAsyncNotifier2 extends _$CountAsyncNotifier2 {
@override
FutureOr<int> build(int a) {
return 1;
}
}

@riverpod
class CountStreamNotifier2 extends _$CountStreamNotifier2 {
@override
Stream<int> build(int a) {
return Stream.value(1);
}
}

0 comments on commit d659ed5

Please sign in to comment.