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