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

Side by Side Diff: tools/dom/templates/html/impl/impl_Node.darttemplate

Issue 11971016: Create IterableMixinWorkaround and move most of the Collections methods there. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo (mappedByList instead of mappedBy). Created 7 years, 11 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of html; 5 part of html;
6 6
7 /** 7 /**
8 * Lazy implementation of the child nodes of an element that does not request 8 * Lazy implementation of the child nodes of an element that does not request
9 * the actual child nodes of an element until strictly necessary greatly 9 * the actual child nodes of an element until strictly necessary greatly
10 * improving performance for the typical cases where it is not required. 10 * improving performance for the typical cases where it is not required.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 Node get single { 46 Node get single {
47 int l = this.length; 47 int l = this.length;
48 if (l == 0) throw new StateError("No elements"); 48 if (l == 0) throw new StateError("No elements");
49 if (l > 1) throw new StateError("More than one element"); 49 if (l > 1) throw new StateError("More than one element");
50 return _this.$dom_firstChild; 50 return _this.$dom_firstChild;
51 } 51 }
52 $endif 52 $endif
53 53
54 Node min([int compare(Node a, Node b)]) { 54 Node min([int compare(Node a, Node b)]) {
55 return Collections.min(this, compare); 55 return IterableMixinWorkaround.min(this, compare);
56 } 56 }
57 57
58 Node max([int compare(Node a, Node b)]) { 58 Node max([int compare(Node a, Node b)]) {
59 return Collections.max(this, compare); 59 return IterableMixinWorkaround.max(this, compare);
60 } 60 }
61 61
62 void add(Node value) { 62 void add(Node value) {
63 _this.$dom_appendChild(value); 63 _this.$dom_appendChild(value);
64 } 64 }
65 65
66 void addLast(Node value) { 66 void addLast(Node value) {
67 _this.$dom_appendChild(value); 67 _this.$dom_appendChild(value);
68 } 68 }
69 69
(...skipping 25 matching lines...) Expand all
95 } 95 }
96 96
97 void operator []=(int index, Node value) { 97 void operator []=(int index, Node value) {
98 _this.$dom_replaceChild(value, this[index]); 98 _this.$dom_replaceChild(value, this[index]);
99 } 99 }
100 100
101 Iterator<Node> get iterator => _this.$dom_childNodes.iterator; 101 Iterator<Node> get iterator => _this.$dom_childNodes.iterator;
102 102
103 // TODO(jacobr): We can implement these methods much more efficiently by 103 // TODO(jacobr): We can implement these methods much more efficiently by
104 // looking up the nodeList only once instead of once per iteration. 104 // looking up the nodeList only once instead of once per iteration.
105 bool contains(Node element) => Collections.contains(this, element); 105 bool contains(Node element) => IterableMixinWorkaround.contains(this, element) ;
106 106
107 void forEach(void f(Node element)) => Collections.forEach(this, f); 107 void forEach(void f(Node element)) => IterableMixinWorkaround.forEach(this, f) ;
108 108
109 dynamic reduce(dynamic initialValue, 109 dynamic reduce(dynamic initialValue,
110 dynamic combine(dynamic previousValue, Node element)) { 110 dynamic combine(dynamic previousValue, Node element)) {
111 return Collections.reduce(this, initialValue, combine); 111 return IterableMixinWorkaround.reduce(this, initialValue, combine);
112 } 112 }
113 113
114 String join([String separator]) { 114 String join([String separator]) {
115 return Collections.joinList(this, separator); 115 return IterableMixinWorkaround.joinList(this, separator);
116 } 116 }
117 117
118 List mappedBy(f(Node element)) => 118 List mappedBy(f(Node element)) {
119 new MappedList<Node, dynamic>(this, f); 119 return IterableMixinWorkaround.mappedByList(this, f);
120 }
120 121
121 Iterable<Node> where(bool f(Node element)) => 122 Iterable<Node> where(bool f(Node element)) {
122 new WhereIterable<Node>(this, f); 123 return IterableMixinWorkaround.where(this, f);
124 }
123 125
124 bool every(bool f(Node element)) => Collections.every(this, f); 126 bool every(bool f(Node element)) => IterableMixinWorkaround.every(this, f);
125 127
126 bool any(bool f(Node element)) => Collections.any(this, f); 128 bool any(bool f(Node element)) => IterableMixinWorkaround.any(this, f);
127 129
128 List<Node> toList() => new List<Node>.from(this); 130 List<Node> toList() => new List<Node>.from(this);
129 Set<Node> toSet() => new Set<Node>.from(this); 131 Set<Node> toSet() => new Set<Node>.from(this);
130 132
131 bool get isEmpty => this.length == 0; 133 bool get isEmpty => this.length == 0;
132 134
133 // From List<Node>: 135 // From List<Node>:
134 136
135 List<Node> take(int n) { 137 List<Node> take(int n) {
136 return new ListView<Node>(this, 0, n); 138 return IterableMixinWorkaround.takeList(this, n);
137 } 139 }
138 140
139 Iterable<Node> takeWhile(bool test(Node value)) { 141 Iterable<Node> takeWhile(bool test(Node value)) {
140 return new TakeWhileIterable<Node>(this, test); 142 return IterableMixinWorkaround.takeWhile(this, test);
141 } 143 }
142 144
143 List<Node> skip(int n) { 145 List<Node> skip(int n) {
144 return new ListView<Node>(this, n, null); 146 return IterableMixinWorkaround.skipList(this, n);
145 } 147 }
146 148
147 Iterable<Node> skipWhile(bool test(Node value)) { 149 Iterable<Node> skipWhile(bool test(Node value)) {
148 return new SkipWhileIterable<Node>(this, test); 150 return IterableMixinWorkaround.skipWhile(this, test);
149 } 151 }
150 152
151 Node firstMatching(bool test(Node value), {Node orElse()}) { 153 Node firstMatching(bool test(Node value), {Node orElse()}) {
152 return Collections.firstMatching(this, test, orElse); 154 return IterableMixinWorkaround.firstMatching(this, test, orElse);
153 } 155 }
154 156
155 Node lastMatching(bool test(Node value), {Node orElse()}) { 157 Node lastMatching(bool test(Node value), {Node orElse()}) {
156 return Collections.lastMatchingInList(this, test, orElse); 158 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse);
157 } 159 }
158 160
159 Node singleMatching(bool test(Node value)) { 161 Node singleMatching(bool test(Node value)) {
160 return Collections.singleMatching(this, test); 162 return IterableMixinWorkaround.singleMatching(this, test);
161 } 163 }
162 164
163 Node elementAt(int index) { 165 Node elementAt(int index) {
164 return this[index]; 166 return this[index];
165 } 167 }
166 168
167 // TODO(jacobr): this could be implemented for child node lists. 169 // TODO(jacobr): this could be implemented for child node lists.
168 // The exception we throw here is misleading. 170 // The exception we throw here is misleading.
169 void sort([int compare(Node a, Node b)]) { 171 void sort([int compare(Node a, Node b)]) {
170 throw new UnsupportedError("Cannot sort immutable List."); 172 throw new UnsupportedError("Cannot sort immutable List.");
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 final Node parent = this.parentNode; 245 final Node parent = this.parentNode;
244 parent.$dom_replaceChild(otherNode, this); 246 parent.$dom_replaceChild(otherNode, this);
245 } catch (e) { 247 } catch (e) {
246 248
247 }; 249 };
248 return this; 250 return this;
249 } 251 }
250 252
251 $!MEMBERS 253 $!MEMBERS
252 } 254 }
OLDNEW
« no previous file with comments | « tools/dom/templates/html/impl/impl_Element.darttemplate ('k') | tools/dom/templates/immutable_list_mixin.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698