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 final Stream<M.NotificationChangeEvent> onChange; |
| 17 |
| 18 void add(M.Notification notification) { |
| 19 _list.add(notification); |
| 20 _onChange.add(new NotificationChangeEvent(this)); |
| 21 } |
| 22 |
| 23 Iterable<M.Notification> list() => _list; |
| 24 |
| 25 void delete(M.Notification notification) { |
| 26 if (_list.remove(notification)) |
| 27 _onChange.add(new NotificationChangeEvent(this)); |
| 28 } |
| 29 |
| 30 void deleteAll() { |
| 31 if (_list.isNotEmpty) { |
| 32 _list.clear(); |
| 33 _onChange.add(new NotificationChangeEvent(this)); |
| 34 } |
| 35 } |
| 36 |
| 37 factory NotificationRepository() { |
| 38 var controller = new StreamController<M.NotificationChangeEvent>(); |
| 39 var stream = controller.stream.asBroadcastStream(); |
| 40 return new NotificationRepository._(controller, stream); |
| 41 } |
| 42 NotificationRepository._(this._onChange, this.onChange); |
| 43 } |
OLD | NEW |