OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library observe.src.list_path_observer; | 5 library observe.src.list_path_observer; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:observe/observe.dart'; | 8 import 'package:observe/observe.dart'; |
9 | 9 |
10 // Inspired by ArrayReduction at: | 10 // Inspired by ArrayReduction at: |
11 // https://raw.github.com/rafaelw/ChangeSummary/master/util/array_reduction.js | 11 // https://raw.github.com/rafaelw/ChangeSummary/master/util/array_reduction.js |
12 // The main difference is we support anything on the rich Dart Iterable API. | 12 // The main difference is we support anything on the rich Dart Iterable API. |
13 | 13 |
14 /// Observes a path starting from each item in the list. | 14 /// Observes a path starting from each item in the list. |
| 15 @deprecated |
15 class ListPathObserver<E, P> extends ChangeNotifier { | 16 class ListPathObserver<E, P> extends ChangeNotifier { |
16 final ObservableList<E> list; | 17 final ObservableList<E> list; |
17 final String _itemPath; | 18 final String _itemPath; |
18 final List<PathObserver> _observers = <PathObserver>[]; | 19 final List<PathObserver> _observers = <PathObserver>[]; |
19 StreamSubscription _sub; | 20 StreamSubscription _sub; |
20 bool _scheduled = false; | 21 bool _scheduled = false; |
21 Iterable<P> _value; | 22 Iterable<P> _value; |
22 | 23 |
23 ListPathObserver(this.list, String path) | 24 ListPathObserver(this.list, String path) |
24 : _itemPath = path { | 25 : _itemPath = path { |
(...skipping 27 matching lines...) Expand all Loading... |
52 void _scheduleReduce(_) { | 53 void _scheduleReduce(_) { |
53 if (_scheduled) return; | 54 if (_scheduled) return; |
54 _scheduled = true; | 55 _scheduled = true; |
55 scheduleMicrotask(_reduce); | 56 scheduleMicrotask(_reduce); |
56 } | 57 } |
57 | 58 |
58 void _observeItems(int lengthAdjust) { | 59 void _observeItems(int lengthAdjust) { |
59 if (lengthAdjust > 0) { | 60 if (lengthAdjust > 0) { |
60 for (int i = 0; i < lengthAdjust; i++) { | 61 for (int i = 0; i < lengthAdjust; i++) { |
61 int len = _observers.length; | 62 int len = _observers.length; |
62 var pathObs = new PathObserver(list, '$len.$_itemPath'); | 63 var pathObs = new PathObserver(list, '[$len].$_itemPath'); |
63 pathObs.open(_scheduleReduce); | 64 pathObs.open(_scheduleReduce); |
64 _observers.add(pathObs); | 65 _observers.add(pathObs); |
65 } | 66 } |
66 } else if (lengthAdjust < 0) { | 67 } else if (lengthAdjust < 0) { |
67 for (int i = 0; i < -lengthAdjust; i++) { | 68 for (int i = 0; i < -lengthAdjust; i++) { |
68 _observers.removeLast().close(); | 69 _observers.removeLast().close(); |
69 } | 70 } |
70 } | 71 } |
71 } | 72 } |
72 } | 73 } |
OLD | NEW |