OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file |
| 4 |
| 5 part of repositories; |
| 6 |
| 7 class NotificationChangeEvent implements M.NotificationChangeEvent { |
| 8 final NotificationRepository repository; |
| 9 NotificationChangeEvent(this.repository); |
| 10 } |
| 11 |
| 12 class NotificationRepository implements M.NotificationRepository { |
| 13 final List<M.Notification> _list = new List<M.Notification>(); |
| 14 |
| 15 final StreamController<M.NotificationChangeEvent> _onChange = |
| 16 new StreamController<M.NotificationChangeEvent>.broadcast(); |
| 17 Stream<M.NotificationChangeEvent> get onChange => _onChange.stream; |
| 18 |
| 19 void add(M.Notification notification) { |
| 20 assert(notification != null); |
| 21 _list.add(notification); |
| 22 _notify(); |
| 23 } |
| 24 |
| 25 Iterable<M.Notification> list() => _list; |
| 26 |
| 27 void delete(M.Notification notification) { |
| 28 if (_list.remove(notification)) |
| 29 _notify(); |
| 30 } |
| 31 |
| 32 void deleteAll() { |
| 33 if (_list.isNotEmpty) { |
| 34 _list.clear(); |
| 35 _notify(); |
| 36 } |
| 37 } |
| 38 |
| 39 NotificationRepository(); |
| 40 |
| 41 void _notify() { |
| 42 _onChange.add(new NotificationChangeEvent(this)); |
| 43 } |
| 44 |
| 45 void deleteWhere(bool test(M.Notification element)) { |
| 46 int length = _list.length; |
| 47 _list.removeWhere(test); |
| 48 if (_list.length != length) _notify(); |
| 49 } |
| 50 |
| 51 void deletePauseEvents({M.Isolate isolate}) { |
| 52 if (isolate == null) { |
| 53 deleteWhere((notification) { |
| 54 return notification is M.EventNotification && |
| 55 M.Event.isPauseEvent(notification.event); |
| 56 }); |
| 57 } else { |
| 58 deleteWhere((notification) { |
| 59 return notification is M.EventNotification && |
| 60 M.Event.isPauseEvent(notification.event) && |
| 61 notification.event.isolate == isolate; |
| 62 }); |
| 63 } |
| 64 } |
| 65 |
| 66 void deleteDisconnectEvents() { |
| 67 deleteWhere((notification) { |
| 68 return notification is M.EventNotification && |
| 69 notification.event is M.ConnectionClosedEvent; |
| 70 }); |
| 71 } |
| 72 } |
OLD | NEW |