rrousselGit / riverpod

A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
https://riverpod.dev
MIT License
5.82k stars 888 forks source link

[quality of life] make `riverpod_annotation` re-export utilities such as `@protected` #3495

Closed lucavenir closed 3 weeks ago

lucavenir commented 3 weeks ago

Is your feature request related to a problem? Please describe. More often than not I write notifiers like the following

import 'package:freezed_annotation/freezed_annotation.dart'; // !

class MyNotifier extends _$MyNotifier {
  @protected  // love it
  @visibleForTesting  // love it
  late MyApi myApi;

  Future<int> build() {
    myApi = ref.watch(myApiProvider);
    return myApi.get();
  }

  Future<void> increment() {
    return update(
      (state) => myApi.incrementFrom(state),
    );
  }
}

Which I do since I want my dependencies to be protected but testable.

Describe the solution you'd like It's just weird that I have to import freezed_annotation or flutter:foundation just to use the above annotations. I'd expect riverpod to offer this because of how handy tests become via these annotations.

Describe alternatives you've considered Maybe I shouldn't protect my dependencies like so, and tests should be done in another way? Either way, it's not too big of a deal.

Are you able to PR this one? Yes I could if approved.

rrousselGit commented 3 weeks ago

Freezed shouldn't be exporting those annotations. I'd remove those in a future release

I don't want packages to export things that are not coming from said package.
The only reason some transitive dependencies are re-exported by the annotation package is because the generated code uses it.

Once we have metaprogramming (and therefore when generated code will be able to define imports on its own), my annotation packages will never export other packages.

lucavenir commented 3 weeks ago

Sorry then, I totally misunderstood the purpose of these re-exports. Fine then, I'll just import flutter/foundation x)