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 _list.add(notification); |
| 21 _notify(); |
| 22 } |
| 23 |
| 24 Iterable<M.Notification> list() => _list; |
| 25 |
| 26 void delete(M.Notification notification) { |
| 27 if (_list.remove(notification)) |
| 28 _notify(); |
| 29 } |
| 30 |
| 31 void deleteAll() { |
| 32 if (_list.isNotEmpty) { |
| 33 _list.clear(); |
| 34 _notify(); |
| 35 } |
| 36 } |
| 37 |
| 38 NotificationRepository(); |
| 39 |
| 40 void _notify() { |
| 41 _onChange.add(new NotificationChangeEvent(this)); |
| 42 } |
| 43 } |
OLD | NEW |