Closed jezsung closed 11 months ago
Patch coverage: 100.00
% and no project coverage change.
Comparison is base (
4f70845
) 99.87% compared to head (4e58095
) 99.87%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Hello! What's the difference with the useStreamListener PR?
I don't like the naming on this hook.
Generally such hooks would be named useOnStreamChange
If the goal is to return a StreamSubscription to cancel the subscription early, that's fine. Although other hooks don't really do this.
Could you add this to the README?
Could you add 100% coverage too?
@rrousselGit I made a few changes based on your feedback.
useStreamSubscription
has been renamed to useOnStreamChange
useOnStreamChange
now can accept null
I tried to keep non trailing comma consistent but some tests with a long description get ugly if the trailing comma gets removed. I think keeping them look clean and readable should be prioritized so I didn't remove them all. What do you think?
Just another thought on this, how about using a callable class to allow syntax like this:
final StreamSubscription subscription = useStream.listen(
onData: (data) => {},
);
I saw the useTextEditingController
is using a callable class to make this syntax possible and it seems really cool.
LGTM, thanks!
Adds a new hook
useStreamSubscription
that allows you to subscribe to a Stream and register callback handlers such asonData
,onError
, andonDone
.Returns the
StreamSubscription
returned by theStream.listen
.CAUTION Awaiting on the returned
StreamSubscription.cancel
never ends on a test. Not sure if this is somehow expected.https://github.com/jezsung/flutter_hooks/blob/53ed52bf3605952f2eb790d8c57b2831684b2479/packages/flutter_hooks/test/use_stream_subscription_test.dart#L207-L209