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

Update event_bus.dart #21

Merged
merged 2 commits into from
Mar 27, 2019
Merged

Update event_bus.dart #21

merged 2 commits into from
Mar 27, 2019

Conversation

Vadaski
Copy link
Contributor

@Vadaski Vadaski commented Mar 26, 2019

Update EventBus constructor to allow custom EventBus.

@marcojakob
Copy link
Owner

Can you provide a small example of how you would use the EventBus like this?

@marcojakob marcojakob mentioned this pull request Mar 26, 2019
@Vadaski
Copy link
Contributor Author

Vadaski commented Mar 26, 2019

@marcojakob
Copy link
Owner

Thanks for the example. It's not very minimal but I get the picture.

What's the reason you are not using the BehaviorSubject directly in your example?

By adding an optional StreamController as parameter to the EventBus constructor the interface becomes a bit confusing. The sync parameter is ignored when a controller is specified.

I think by using special controllers, the behavior of EventBus can become hard to understand. I think it's better to use something like BehaviorSubject directly so that the special behavior is expected.

@Vadaski
Copy link
Contributor Author

Vadaski commented Mar 27, 2019

Thank you to remind me! I agree with the sync parameter will ignored when a controller is specified.I overlooked it.

This example shows two pages rely on CountEvent.They use StreamBuilder to listen for this event. If I use StreamController.broadcast I have to fire the Event after streamBuilder listen this stream.Otherwise I won't get the message.
BehaviorSubject can add last event to listener when they first listen.I don't need to care when listener listens.So I just fire the event before streamBuilder first listen.As you can see I fired the first CountEvent in the main function. EventBus become more powerful and easy to use.

I think using another constructor might be the better solution.

  EventBus({bool sync = false})
      : _streamController = StreamController.broadcast(sync: sync);

  EventBus.custom(StreamController controller) : _streamController = controller;

@marcojakob marcojakob merged commit fd4847b into marcojakob:master Mar 27, 2019
@marcojakob
Copy link
Owner

Thanks @Vadaski. I've made a small change and merged it. It's now as v1.1.0 on pub.

@Vadaski
Copy link
Contributor Author

Vadaski commented Mar 28, 2019

Great! I'm happy to make eventbus better. Thank you@marcojakob!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants