| 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 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 } | 422 } |
| 423 | 423 |
| 424 getInstanceFragment(syntax) { | 424 getInstanceFragment(syntax) { |
| 425 if (syntax != null) { | 425 if (syntax != null) { |
| 426 return syntax.getInstanceFragment(_templateElement); | 426 return syntax.getInstanceFragment(_templateElement); |
| 427 } | 427 } |
| 428 return _templateElement.createInstance(); | 428 return _templateElement.createInstance(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 void _handleChanges(List<ChangeRecord> splices) { | 431 void _handleChanges(List<ChangeRecord> splices) { |
| 432 var syntax = TemplateElement.syntax[_templateElement.attributes['syntax']]; | 432 var template = _templateElement; |
| 433 var syntax = TemplateElement.syntax[template.attributes['syntax']]; |
| 434 |
| 435 if (template.parentNode == null || template.document.window == null) { |
| 436 // TODO(jmesserly): this is a little different than the MDV code, which |
| 437 // removes _templateIterator from all instances (via the weak table). |
| 438 // I think it has a similar effect. It might be a no-op. |
| 439 removeAllInstances(); |
| 440 abandon(); |
| 441 return; |
| 442 } |
| 433 | 443 |
| 434 for (var splice in splices) { | 444 for (var splice in splices) { |
| 435 if (splice is! ListChangeRecord) continue; | 445 if (splice is! ListChangeRecord) continue; |
| 436 | 446 |
| 437 for (int i = 0; i < splice.removedCount; i++) { | 447 for (int i = 0; i < splice.removedCount; i++) { |
| 438 removeInstanceAt(splice.index); | 448 removeInstanceAt(splice.index); |
| 439 } | 449 } |
| 440 | 450 |
| 441 for (var addIndex = splice.index; | 451 for (var addIndex = splice.index; |
| 442 addIndex < splice.index + splice.addedCount; | 452 addIndex < splice.index + splice.addedCount; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 456 | 466 |
| 457 void unobserve() { | 467 void unobserve() { |
| 458 if (_sub == null) return; | 468 if (_sub == null) return; |
| 459 _sub.cancel(); | 469 _sub.cancel(); |
| 460 _sub = null; | 470 _sub = null; |
| 461 } | 471 } |
| 462 | 472 |
| 463 void abandon() { | 473 void abandon() { |
| 464 unobserve(); | 474 unobserve(); |
| 465 _valueBinding.cancel(); | 475 _valueBinding.cancel(); |
| 476 terminators.clear(); |
| 466 inputs.dispose(); | 477 inputs.dispose(); |
| 467 } | 478 } |
| 468 } | 479 } |
| OLD | NEW |