Skip to content

Commit

Permalink
Rename to customController
Browse files Browse the repository at this point in the history
  • Loading branch information
marcojakob committed Mar 27, 2019
1 parent fd4847b commit 9dd8370
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ User myUser = new User('Mickey');
eventBus.fire(new UserLoggedInEvent(myUser));
```

## Using Custom Stream Controllers

Instead of using the default `StreamController` you can use the following constructor
to provide your own.

An example would be to use an [RxDart](https://pub.dartlang.org/packages/rxdart) Subject
as the controller.

```dart
import 'package:rxdart/rxdart.dart';
EventBus behaviorBus = EventBus.customController(BehaviorSubject());
```


## Running / Building / Testing

- Run from the terminal: `webdev serve`
Expand Down
11 changes: 7 additions & 4 deletions lib/event_bus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ class EventBus {
/// completed.
EventBus({bool sync = false})
: _streamController = StreamController.broadcast(sync: sync);

/// Also you can pass your own StreamController as EventBus to extend StreamController
/// such like Subject in RxDart.
EventBus.custom(StreamController controller) : _streamController = controller;

/// Instead of using the default [StreamController] you can use this constructor
/// to pass your own controller.
///
/// An example would be to use an RxDart Subject as the controller.
EventBus.customController(StreamController controller)
: _streamController = controller;

/// Listens for events of Type [T] and its subtypes.
///
Expand Down

0 comments on commit 9dd8370

Please sign in to comment.