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

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

Issue 11956039: Revert "Create IterableMixinWorkaround and move most of the Collections methods there." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 IterableMixinWorkaround.min(this, compare); 55 return Collections.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 IterableMixinWorkaround.max(this, compare); 59 return Collections.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) => IterableMixinWorkaround.contains(this, element) ; 105 bool contains(Node element) => Collections.contains(this, element);
106 106
107 void forEach(void f(Node element)) => IterableMixinWorkaround.forEach(this, f) ; 107 void forEach(void f(Node element)) => Collections.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 IterableMixinWorkaround.reduce(this, initialValue, combine); 111 return Collections.reduce(this, initialValue, combine);
112 } 112 }
113 113
114 String join([String separator]) { 114 String join([String separator]) {
115 return IterableMixinWorkaround.joinList(this, separator); 115 return Collections.joinList(this, separator);
116 } 116 }
117 117
118 List mappedBy(f(Node element)) { 118 List mappedBy(f(Node element)) =>
119 return IterableMixinWorkaround.mappedByList(this, f); 119 new MappedList<Node, dynamic>(this, f);
120 }
121 120
122 Iterable<Node> where(bool f(Node element)) { 121 Iterable<Node> where(bool f(Node element)) =>
123 return IterableMixinWorkaround.where(this, f); 122 new WhereIterable<Node>(this, f);
124 }
125 123
126 bool every(bool f(Node element)) => IterableMixinWorkaround.every(this, f); 124 bool every(bool f(Node element)) => Collections.every(this, f);
127 125
128 bool any(bool f(Node element)) => IterableMixinWorkaround.any(this, f); 126 bool any(bool f(Node element)) => Collections.any(this, f);
129 127
130 List<Node> toList() => new List<Node>.from(this); 128 List<Node> toList() => new List<Node>.from(this);
131 Set<Node> toSet() => new Set<Node>.from(this); 129 Set<Node> toSet() => new Set<Node>.from(this);
132 130
133 bool get isEmpty => this.length == 0; 131 bool get isEmpty => this.length == 0;
134 132
135 // From List<Node>: 133 // From List<Node>:
136 134
137 List<Node> take(int n) { 135 List<Node> take(int n) {
138 return IterableMixinWorkaround.takeList(this, n); 136 return new ListView<Node>(this, 0, n);
139 } 137 }
140 138
141 Iterable<Node> takeWhile(bool test(Node value)) { 139 Iterable<Node> takeWhile(bool test(Node value)) {
142 return IterableMixinWorkaround.takeWhile(this, test); 140 return new TakeWhileIterable<Node>(this, test);
143 } 141 }
144 142
145 List<Node> skip(int n) { 143 List<Node> skip(int n) {
146 return IterableMixinWorkaround.skipList(this, n); 144 return new ListView<Node>(this, n, null);
147 } 145 }
148 146
149 Iterable<Node> skipWhile(bool test(Node value)) { 147 Iterable<Node> skipWhile(bool test(Node value)) {
150 return IterableMixinWorkaround.skipWhile(this, test); 148 return new SkipWhileIterable<Node>(this, test);
151 } 149 }
152 150
153 Node firstMatching(bool test(Node value), {Node orElse()}) { 151 Node firstMatching(bool test(Node value), {Node orElse()}) {
154 return IterableMixinWorkaround.firstMatching(this, test, orElse); 152 return Collections.firstMatching(this, test, orElse);
155 } 153 }
156 154
157 Node lastMatching(bool test(Node value), {Node orElse()}) { 155 Node lastMatching(bool test(Node value), {Node orElse()}) {
158 return IterableMixinWorkaround.lastMatchingInList(this, test, orElse); 156 return Collections.lastMatchingInList(this, test, orElse);
159 } 157 }
160 158
161 Node singleMatching(bool test(Node value)) { 159 Node singleMatching(bool test(Node value)) {
162 return IterableMixinWorkaround.singleMatching(this, test); 160 return Collections.singleMatching(this, test);
163 } 161 }
164 162
165 Node elementAt(int index) { 163 Node elementAt(int index) {
166 return this[index]; 164 return this[index];
167 } 165 }
168 166
169 // TODO(jacobr): this could be implemented for child node lists. 167 // TODO(jacobr): this could be implemented for child node lists.
170 // The exception we throw here is misleading. 168 // The exception we throw here is misleading.
171 void sort([int compare(Node a, Node b)]) { 169 void sort([int compare(Node a, Node b)]) {
172 throw new UnsupportedError("Cannot sort immutable List."); 170 throw new UnsupportedError("Cannot sort immutable List.");
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 final Node parent = this.parentNode; 243 final Node parent = this.parentNode;
246 parent.$dom_replaceChild(otherNode, this); 244 parent.$dom_replaceChild(otherNode, this);
247 } catch (e) { 245 } catch (e) {
248 246
249 }; 247 };
250 return this; 248 return this;
251 } 249 }
252 250
253 $!MEMBERS 251 $!MEMBERS
254 } 252 }
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