rrousselGit / state_notifier

ValueNotifier, but outside Flutter and with some extra perks
MIT License
311 stars 28 forks source link

Stream returned `stream` getter should notify with the current state immediately on listen #78

Closed maBarabas closed 1 year ago

maBarabas commented 1 year ago

Is your feature request related to a problem? Please describe.

StreamNotifier.steam returns a broadcast stream that is idle until the state is set. It should instead notify the current state immediately.

Describe the solution you'd like

The stream getter should return a ValueStream constructed using BehaviorSubject.seeded or something similar. This variant of the stream always notifies with the last known value on listen, which is consistent with how the StateNotifier.addListener works.

Describe alternatives you've considered

This extension is consistent with addListener:

extension _StateEx<T> on StateNotifier<T> {
  ValueStream<T> get valueStream {
    // ignore: invalid_use_of_protected_member
    return stream.shareValueSeeded(state);
  }
}
rrousselGit commented 1 year ago

Hello!

This would be breaking and likely require an extra dependency or a lot of work. I have no plan to do such a thing. So while I appreciate the request, I'll close this as it won't be worked on :)