Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Unified Diff: sdk/lib/mdv_observe_impl/mdv_observe_impl.dart

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/mime_multipart_parser.dart ('k') | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e612f3a3e562ad9920139ba6ca6ebf91ea9df2ef 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>>>();
}
- 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) {
- // TODO(jmesserly): make "changes" immutable
- _observers.add(changes);
+ var observers =
+ _observers.toList();
+ for (var observer in observers) {
+ if (_observers.contains(observer)) {
+ // TODO(jmesserly): make "changes" immutable
+ observer.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.
« no previous file with comments | « sdk/lib/io/mime_multipart_parser.dart ('k') | tests/lib/async/stream_controller_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698