-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the
HierarchicalEventBus
to a separate library to be able to r…
…emove `dart:mirrors` from normal `EventBus` Users of the hierarchical event bus must import `event_bus_hierarchical.dart` and replace the use of the factory constructor `EventBus.hierarchical()` with the `HierarchicalEventBus` constructor.
- Loading branch information
Showing
8 changed files
with
105 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.buildlog | ||
.DS_Store | ||
.idea | ||
.pub/ | ||
build/ | ||
packages | ||
.project | ||
pubspec.lock | ||
pubspec.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
library event_bus.hierarchical; | ||
|
||
import 'dart:async'; | ||
|
||
@MirrorsUsed(symbols: '*') // Do not keep any names. | ||
import 'dart:mirrors'; | ||
|
||
import 'event_bus.dart'; | ||
export 'event_bus.dart'; | ||
|
||
/** | ||
* A [HierarchicalEventBus] that filters events by event class **including** | ||
* its subclasses. | ||
* | ||
* Note: This currently only works with classes **extending** other classes | ||
* and not with **implementing** an interface. We might have to wait for | ||
* https://code.google.com/p/dart/issues/detail?id=20756 to enable interfaces. | ||
*/ | ||
class HierarchicalEventBus extends EventBus { | ||
|
||
/** | ||
* Creates a [HierarchicalEventBus]. | ||
* | ||
* If [sync] is true, events are passed directly to the stream's listeners | ||
* during an [fire] call. If false (the default), the event will be passed to | ||
* the listeners at a later time, after the code creating the event has | ||
* completed. | ||
*/ | ||
HierarchicalEventBus({bool sync: false}) : super(sync: sync); | ||
|
||
/** | ||
* Listens for events of [eventType] and of all subclasses of [eventType]. | ||
* | ||
* The returned [Stream] is a broadcast stream so multiple subscriptions are | ||
* allowed. | ||
* | ||
* Each listener is handled independently, and if they pause, only the pausing | ||
* listener is affected. A paused listener will buffer events internally until | ||
* unpaused or canceled. So it's usually better to just cancel and later | ||
* subscribe again (avoids memory leak). | ||
*/ | ||
Stream on([Type eventType]) { | ||
return streamController.stream.where((event) => eventType == null || | ||
reflect(event).type.isSubclassOf(reflectClass(eventType))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
name: event_bus | ||
version: 0.3.0+3 | ||
version: 0.4.0 | ||
author: Marco Jakob <[email protected]> | ||
description: A simple Event Bus using Dart Streams for decoupling applications | ||
homepage: http://code.makery.ch/library/dart-event-bus | ||
documentation: http://www.dartdocs.org/documentation/event_bus/latest/ | ||
dev_dependencies: | ||
browser: '>=0.10.0 <0.11.0' | ||
logging: '>=0.9.0 <0.10.0' | ||
logging: '>=0.10.0 <0.11.0' | ||
unittest: '>=0.11.0 <0.12.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters