| 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 /** | 5 /** |
| 6 * Custom DOM elements. | 6 * Custom DOM elements. |
| 7 * | 7 * |
| 8 * This library provides access to the Polymer project's | 8 * This library provides access to the Polymer project's |
| 9 * [Custom Elements] | 9 * [Custom Elements] |
| 10 * (http://www.polymer-project.org/platform/custom-elements.html) | 10 * (http://www.polymer-project.org/platform/custom-elements.html) |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 CustomElement element = ctor(); | 618 CustomElement element = ctor(); |
| 619 element.host = node; | 619 element.host = node; |
| 620 | 620 |
| 621 // TODO(jmesserly): replace lifecycle stuff with a proper polyfill. | 621 // TODO(jmesserly): replace lifecycle stuff with a proper polyfill. |
| 622 element.created(); | 622 element.created(); |
| 623 | 623 |
| 624 _registerLifecycleInsert(element); | 624 _registerLifecycleInsert(element); |
| 625 } | 625 } |
| 626 | 626 |
| 627 void _registerLifecycleInsert(CustomElement element) { | 627 void _registerLifecycleInsert(CustomElement element) { |
| 628 runAsync(() { | 628 scheduleMicrotask(() { |
| 629 // TODO(jmesserly): bottom up or top down insert? | 629 // TODO(jmesserly): bottom up or top down insert? |
| 630 var node = element.host; | 630 var node = element.host; |
| 631 | 631 |
| 632 // TODO(jmesserly): need a better check to see if the node has been removed. | 632 // TODO(jmesserly): need a better check to see if the node has been removed. |
| 633 if (node.parentNode == null) return; | 633 if (node.parentNode == null) return; |
| 634 | 634 |
| 635 _registerLifecycleRemove(element); | 635 _registerLifecycleRemove(element); |
| 636 element.inserted(); | 636 element.inserted(); |
| 637 }); | 637 }); |
| 638 } | 638 } |
| 639 | 639 |
| 640 void _registerLifecycleRemove(CustomElement element) { | 640 void _registerLifecycleRemove(CustomElement element) { |
| 641 // TODO(jmesserly): need fallback or polyfill for MutationObserver. | 641 // TODO(jmesserly): need fallback or polyfill for MutationObserver. |
| 642 if (!MutationObserver.supported) return; | 642 if (!MutationObserver.supported) return; |
| 643 | 643 |
| 644 new MutationObserver((records, observer) { | 644 new MutationObserver((records, observer) { |
| 645 var node = element.host; | 645 var node = element.host; |
| 646 for (var record in records) { | 646 for (var record in records) { |
| 647 for (var removed in record.removedNodes) { | 647 for (var removed in record.removedNodes) { |
| 648 if (identical(node, removed)) { | 648 if (identical(node, removed)) { |
| 649 observer.disconnect(); | 649 observer.disconnect(); |
| 650 element.removed(); | 650 element.removed(); |
| 651 return; | 651 return; |
| 652 } | 652 } |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 }).observe(element.parentNode, childList: true); | 655 }).observe(element.parentNode, childList: true); |
| 656 } | 656 } |
| OLD | NEW |