| OLD | NEW |
| 1 Sky Event Model | 1 Sky Event Model |
| 2 =============== | 2 =============== |
| 3 | 3 |
| 4 ```dart | 4 ```dart |
| 5 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 | 7 |
| 8 class ExceptionAndStackTrace<T> { | 8 class ExceptionAndStackTrace<T> { |
| 9 const ExceptionAndStackTrace(this.exception, this.stackTrace); | 9 const ExceptionAndStackTrace(this.exception, this.stackTrace); |
| 10 final T exception; | 10 final T exception; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 typedef bool Filter<T>(T t); | 25 typedef bool Filter<T>(T t); |
| 26 typedef void Handler<T>(T t); | 26 typedef void Handler<T>(T t); |
| 27 | 27 |
| 28 class DispatcherController<T> { | 28 class DispatcherController<T> { |
| 29 DispatcherController() : dispatcher = new Dispatcher<T>(); | 29 DispatcherController() : dispatcher = new Dispatcher<T>(); |
| 30 final Dispatcher<T> dispatcher; | 30 final Dispatcher<T> dispatcher; |
| 31 void add(T data) => dispatcher._add(data); | 31 void add(T data) => dispatcher._add(data); |
| 32 } | 32 } |
| 33 | 33 |
| 34 class Pair<A, B> { | |
| 35 const Pair(this.a, this.b); | |
| 36 final A a; | |
| 37 final B b; | |
| 38 } | |
| 39 | |
| 40 class Dispatcher<T> { | 34 class Dispatcher<T> { |
| 41 List<Pair<Handler, ZoneUnaryCallback>> _listeners; | 35 List<Pair<Handler, ZoneUnaryCallback>> _listeners; |
| 42 void listen(Handler<T> handler) { | 36 void listen(Handler<T> handler) { |
| 43 // you should not throw out of this handler | 37 // you should not throw out of this handler |
| 44 if (_listeners == null) | 38 if (_listeners == null) |
| 45 _listeners = new List<Pair<Handler, ZoneUnaryCallback>>(); | 39 _listeners = new List<Pair<Handler, ZoneUnaryCallback>>(); |
| 46 _listeners.add(new Pair<Handler, ZoneUnaryCallback>(handler, Zone.current.bi
ndUnaryCallback(handler))); | 40 _listeners.add(new Pair<Handler, ZoneUnaryCallback>(handler, Zone.current.bi
ndUnaryCallback(handler))); |
| 47 } | 41 } |
| 48 bool unlisten(Handler<T> handler) { | 42 bool unlisten(Handler<T> handler) { |
| 49 if (_listeners == null) | 43 if (_listeners == null) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 throw exceptions; | 183 throw exceptions; |
| 190 return event.result; | 184 return event.result; |
| 191 } | 185 } |
| 192 | 186 |
| 193 void _dispatchEventLocally(Event event) { | 187 void _dispatchEventLocally(Event event) { |
| 194 event._currentTarget = this; | 188 event._currentTarget = this; |
| 195 _eventsController.add(event); | 189 _eventsController.add(event); |
| 196 } | 190 } |
| 197 } | 191 } |
| 198 ``` | 192 ``` |
| OLD | NEW |