Index: sdk/lib/mdv_observe_impl/mdv_observe_impl.dart |
diff --git a/sdk/lib/mdv_observe_impl/mdv_observe_impl.dart b/sdk/lib/mdv_observe_impl/mdv_observe_impl.dart |
index e56554bce82d3cbac789836e9b70d9b126b372f3..9f477aa6fa4353fb2e9137109350a611b3292713 100644 |
--- a/sdk/lib/mdv_observe_impl/mdv_observe_impl.dart |
+++ b/sdk/lib/mdv_observe_impl/mdv_observe_impl.dart |
@@ -63,24 +63,38 @@ typedef ObservableBase = Object with ObservableMixin; |
* call [notifyPropertyChange]. See that method for an example. |
*/ |
abstract class ObservableMixin implements Observable { |
- StreamController<List<ChangeRecord>> _observers; |
+ Set<StreamController<List<ChangeRecord>>> _observers; |
Stream<List<ChangeRecord>> _stream; |
List<ChangeRecord> _changes; |
Stream<List<ChangeRecord>> get changes { |
if (_observers == null) { |
- _observers = new StreamController<List<ChangeRecord>>(); |
- _stream = _observers.stream.asBroadcastStream(); |
+ _observers = new Set<StreamController<List<ChangeRecord>>>(); |
Jennifer Messerly
2013/05/24 23:28:08
fwiw... this seems awfully complicated for somethi
Lasse Reichstein Nielsen
2013/05/27 08:04:53
Yes, we introduced StreamController.multiplex afte
|
} |
- return _stream; |
+ StreamController controller; |
+ controller = new StreamController( |
+ onListen: () { |
+ _observers.add(controller); |
+ }, |
+ onCancel: () { |
+ _observers.remove(controller); |
+ } |
+ ); |
+ return controller.stream; |
} |
void _deliverChanges() { |
var changes = _changes; |
_changes = null; |
if (hasObservers && changes != null) { |
+ List<StreamController<List<ChangeRecord>>> observers = |
Jennifer Messerly
2013/05/24 23:28:08
style nit, I'd use "var" here and below:
http://w
Lasse Reichstein Nielsen
2013/05/27 08:04:53
It's your code, so ok.
|
+ _observers.toList(); |
+ for (StreamController<List<ChangeRecord>> observer in observers) { |
+ if (_observers.contains(observer)) { |
+ observer.add(changes); |
+ } |
+ } |
// TODO(jmesserly): make "changes" immutable |
Jennifer Messerly
2013/05/24 18:47:55
keep this comment by the "observer.add(changes);"
Lasse Reichstein Nielsen
2013/05/27 08:04:53
Ofcourse :)
|
- _observers.add(changes); |
} |
} |
@@ -88,7 +102,7 @@ abstract class ObservableMixin implements Observable { |
* True if this object has any observers, and should call |
* [notifyPropertyChange] for changes. |
*/ |
- bool get hasObservers => _observers != null && _observers.hasListener; |
+ bool get hasObservers => _observers != null && !_observers.isEmpty; |
/** |
* Notify that the field [name] of this object has been changed. |