| Index: sky/specs/events.md
|
| diff --git a/sky/specs/events.md b/sky/specs/events.md
|
| index 18cbb33097a86795207d7e2796b72be917124112..56416611497bb7add80b1705ec19b000518f94a6 100644
|
| --- a/sky/specs/events.md
|
| +++ b/sky/specs/events.md
|
| @@ -75,14 +75,7 @@ class Dispatcher<T> {
|
| throw exceptions;
|
| }
|
|
|
| - Dispatcher<T> where(Filter<T> filter) {
|
| - var subdispatcher = new Dispatcher<T>();
|
| - listen((T data) {
|
| - if (filter(data))
|
| - subdispatcher._add(data);
|
| - });
|
| - return subdispatcher;
|
| - }
|
| + Dispatcher<T> where(Filter<T> filter) => new WhereDispatcher<T>(this, filter);
|
|
|
| Dispatcher<T> until(Filter<T> filter) {
|
| var subdispatcher = new Dispatcher<T>();
|
| @@ -111,6 +104,28 @@ class Dispatcher<T> {
|
| }
|
| }
|
|
|
| +class WhereDispatcher<T> extends Dispatcher {
|
| + WhereDispatcher(this.parent, this.filter) : super();
|
| + Dispatcher parent;
|
| + Filter filter;
|
| +
|
| + void listen(Handler<T> handler) {
|
| + if (_listeners == null || _listeners.length == 0)
|
| + parent.listen(_handler);
|
| + super.listen(handler);
|
| + }
|
| + bool unlisten(Handler<T> handler) {
|
| + var result = super.unlisten(handler);
|
| + if (result && _listeners.length == 0)
|
| + parent.unlisten(_handler);
|
| + return result;
|
| + }
|
| + void _handler(T data) {
|
| + if (filter(data))
|
| + _add(data);
|
| + }
|
| +}
|
| +
|
| abstract class Event<ReturnType> {
|
| Event() { init(); }
|
| void init() { }
|
|
|