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

Side by Side Diff: pkg/mdv/lib/src/template_iterator.dart

Issue 19672018: [mdv] getTeminatorAt recurses infinitely if template is its own terminator (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
« no previous file with comments | « no previous file | pkg/mdv/test/template_element_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of mdv; 5 part of mdv;
6 6
7 // This code is a port of Model-Driven-Views: 7 // This code is a port of Model-Driven-Views:
8 // https://github.com/polymer-project/mdv 8 // https://github.com/polymer-project/mdv
9 // The code mostly comes from src/template_element.js 9 // The code mostly comes from src/template_element.js
10 10
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 226
227 int addedCount = iteratedValue.length; 227 int addedCount = iteratedValue.length;
228 var removedCount = oldValue is List ? (oldValue as List).length : 0; 228 var removedCount = oldValue is List ? (oldValue as List).length : 0;
229 if (addedCount == 0 && removedCount == 0) return; // nothing to do. 229 if (addedCount == 0 && removedCount == 0) return; // nothing to do.
230 230
231 _handleChanges([new ListChangeRecord(0, addedCount: addedCount, 231 _handleChanges([new ListChangeRecord(0, addedCount: addedCount,
232 removedCount: removedCount)]); 232 removedCount: removedCount)]);
233 } 233 }
234 234
235 Node getTerminatorAt(int index) { 235 Node getTerminatorAt(int index) {
justinfagnani 2013/07/23 19:59:40 for my own education, what's a terminator?
Jennifer Messerly 2013/07/23 20:13:00 you know almost as much as I do :) from the code,
236 if (index == -1) return _templateElement; 236 if (index == -1) return _templateElement;
237 var terminator = terminators[index]; 237 var terminator = terminators[index];
238 if (terminator is Element && (terminator as Element).isTemplate) { 238 if (terminator is Element && (terminator as Element).isTemplate &&
239 !identical(terminator, _templateElement)) {
239 var subIterator = _mdv(terminator)._templateIterator; 240 var subIterator = _mdv(terminator)._templateIterator;
240 if (subIterator != null) { 241 if (subIterator != null) {
241 return subIterator.getTerminatorAt(subIterator.terminators.length - 1); 242 return subIterator.getTerminatorAt(subIterator.terminators.length - 1);
242 } 243 }
243 } 244 }
244 245
245 return terminator; 246 return terminator;
246 } 247 }
247 248
248 void insertInstanceAt(int index, List<Node> instanceNodes) { 249 void insertInstanceAt(int index, List<Node> instanceNodes) {
(...skipping 11 matching lines...) Expand all
260 } 261 }
261 262
262 List<Node> extractInstanceAt(int index) { 263 List<Node> extractInstanceAt(int index) {
263 var instanceNodes = <Node>[]; 264 var instanceNodes = <Node>[];
264 var previousTerminator = getTerminatorAt(index - 1); 265 var previousTerminator = getTerminatorAt(index - 1);
265 var terminator = getTerminatorAt(index); 266 var terminator = getTerminatorAt(index);
266 terminators.removeAt(index); 267 terminators.removeAt(index);
267 268
268 var parent = _templateElement.parentNode; 269 var parent = _templateElement.parentNode;
269 while (terminator != previousTerminator) { 270 while (terminator != previousTerminator) {
270 var node = terminator; 271 var node = previousTerminator.nextNode;
271 terminator = node.previousNode; 272 if (node == terminator) terminator = previousTerminator;
272 node.remove(); 273 node.remove();
273 instanceNodes.add(node); 274 instanceNodes.add(node);
274 } 275 }
275 return instanceNodes; 276 return instanceNodes;
276 } 277 }
277 278
278 getInstanceModel(model, String syntax) { 279 getInstanceModel(model, String syntax) {
279 var delegate = TemplateElement.syntax[syntax]; 280 var delegate = TemplateElement.syntax[syntax];
280 if (delegate != null) { 281 if (delegate != null) {
281 return delegate.getInstanceModel(_templateElement, model); 282 return delegate.getInstanceModel(_templateElement, model);
(...skipping 25 matching lines...) Expand all
307 return; 308 return;
308 } 309 }
309 310
310 // TODO(jmesserly): IdentityMap matches JS semantics, but it's O(N) right 311 // TODO(jmesserly): IdentityMap matches JS semantics, but it's O(N) right
311 // now. See http://dartbug.com/4161. 312 // now. See http://dartbug.com/4161.
312 var instanceCache = new IdentityMap(); 313 var instanceCache = new IdentityMap();
313 var removeDelta = 0; 314 var removeDelta = 0;
314 for (var splice in splices) { 315 for (var splice in splices) {
315 for (int i = 0; i < splice.removedCount; i++) { 316 for (int i = 0; i < splice.removedCount; i++) {
316 var instanceNodes = extractInstanceAt(splice.index + removeDelta); 317 var instanceNodes = extractInstanceAt(splice.index + removeDelta);
318 if (instanceNodes.length == 0) continue;
317 var model = _mdv(instanceNodes.first)._templateInstance.model; 319 var model = _mdv(instanceNodes.first)._templateInstance.model;
318 instanceCache[model] = instanceNodes; 320 instanceCache[model] = instanceNodes;
319 } 321 }
320 322
321 removeDelta -= splice.addedCount; 323 removeDelta -= splice.addedCount;
322 } 324 }
323 325
324 for (var splice in splices) { 326 for (var splice in splices) {
325 for (var addIndex = splice.index; 327 for (var addIndex = splice.index;
326 addIndex < splice.index + splice.addedCount; 328 addIndex < splice.index + splice.addedCount;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 nodeExt._templateIterator = null; 364 nodeExt._templateIterator = null;
363 } 365 }
364 } 366 }
365 367
366 _nodeOrCustom(node).unbindAll(); 368 _nodeOrCustom(node).unbindAll();
367 for (var c = node.firstChild; c != null; c = c.nextNode) { 369 for (var c = node.firstChild; c != null; c = c.nextNode) {
368 _unbindAllRecursively(c); 370 _unbindAllRecursively(c);
369 } 371 }
370 } 372 }
371 } 373 }
OLDNEW
« no previous file with comments | « no previous file | pkg/mdv/test/template_element_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698