| 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 /** | 14 /// Observes a path starting from each item in the list. |
| 15 * Observes a path starting from each item in the list. | |
| 16 */ | |
| 17 class ListPathObserver<E, P> extends ChangeNotifier { | 15 class ListPathObserver<E, P> extends ChangeNotifier { |
| 18 final ObservableList<E> list; | 16 final ObservableList<E> list; |
| 19 final String _itemPath; | 17 final String _itemPath; |
| 20 final List<PathObserver> _observers = <PathObserver>[]; | 18 final List<PathObserver> _observers = <PathObserver>[]; |
| 21 final List<StreamSubscription> _subs = <StreamSubscription>[]; | 19 final List<StreamSubscription> _subs = <StreamSubscription>[]; |
| 22 StreamSubscription _sub; | 20 StreamSubscription _sub; |
| 23 bool _scheduled = false; | 21 bool _scheduled = false; |
| 24 Iterable<P> _value; | 22 Iterable<P> _value; |
| 25 | 23 |
| 26 ListPathObserver(this.list, String path) | 24 ListPathObserver(this.list, String path) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 66 } |
| 69 } else if (lengthAdjust < 0) { | 67 } else if (lengthAdjust < 0) { |
| 70 for (int i = 0; i < -lengthAdjust; i++) { | 68 for (int i = 0; i < -lengthAdjust; i++) { |
| 71 _subs.removeLast().cancel(); | 69 _subs.removeLast().cancel(); |
| 72 } | 70 } |
| 73 int len = _observers.length; | 71 int len = _observers.length; |
| 74 _observers.removeRange(len + lengthAdjust, len); | 72 _observers.removeRange(len + lengthAdjust, len); |
| 75 } | 73 } |
| 76 } | 74 } |
| 77 } | 75 } |
| OLD | NEW |