Index: runtime/observatory/lib/src/repositories/notification.dart |
diff --git a/runtime/observatory/lib/src/repositories/notification.dart b/runtime/observatory/lib/src/repositories/notification.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2e58b213e7594ef59b86eb46b98396fdd06cc3b8 |
--- /dev/null |
+++ b/runtime/observatory/lib/src/repositories/notification.dart |
@@ -0,0 +1,43 @@ |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file |
+ |
+part of repositories; |
+ |
+class NotificationChangeEvent implements M.NotificationChangeEvent { |
+ final NotificationRepository repository; |
+ NotificationChangeEvent(this.repository); |
+} |
+ |
+class NotificationRepository implements M.NotificationRepository { |
+ final List<M.Notification> _list = new List<M.Notification>(); |
+ |
+ final StreamController<M.NotificationChangeEvent> _onChange; |
+ final Stream<M.NotificationChangeEvent> onChange; |
+ |
+ void add(M.Notification notification) { |
+ _list.add(notification); |
+ _onChange.add(new NotificationChangeEvent(this)); |
+ } |
+ |
+ Iterable<M.Notification> list() => _list; |
+ |
+ void delete(M.Notification notification) { |
+ if (_list.remove(notification)) |
+ _onChange.add(new NotificationChangeEvent(this)); |
+ } |
+ |
+ void deleteAll() { |
+ if (_list.isNotEmpty) { |
+ _list.clear(); |
+ _onChange.add(new NotificationChangeEvent(this)); |
+ } |
+ } |
+ |
+ factory NotificationRepository() { |
+ var controller = new StreamController<M.NotificationChangeEvent>(); |
+ var stream = controller.stream.asBroadcastStream(); |
+ return new NotificationRepository._(controller, stream); |
+ } |
+ NotificationRepository._(this._onChange, this.onChange); |
+} |