Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: pkg/observe/lib/src/list_path_observer.dart

Issue 420673002: Roll polymer packages to version 0.3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698