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

Unified Diff: pkg/custom_element/lib/custom_element.dart

Issue 36373004: remove old custom_element polyfill (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/custom_element/lib/src/attribute_map.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/custom_element/lib/custom_element.dart
diff --git a/pkg/custom_element/lib/custom_element.dart b/pkg/custom_element/lib/custom_element.dart
index b4225eee9eb7d3e2c22571eaaecb279e712e39e7..acabe007768493b465deec40deedd26a5f73c579 100644
--- a/pkg/custom_element/lib/custom_element.dart
+++ b/pkg/custom_element/lib/custom_element.dart
@@ -22,95 +22,16 @@ import 'dart:html';
import 'package:meta/meta.dart';
import 'src/custom_tag_name.dart';
-part 'src/attribute_map.dart';
-
-// TODO(jmesserly): replace with a real custom element polyfill.
-// This is just something temporary.
-/**
- * *Warning*: this implementation is a work in progress. It only implements
- * the specification partially.
- *
- * Registers a custom HTML element with [localName] and the associated
- * constructor. This will ensure the element is detected and
- *
- * See the specification at:
- * <https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html>
- */
-void registerCustomElement(String localName, CustomElement create()) {
- if (_customElements == null) {
- _customElements = {};
- // TODO(jmesserly): use MutationObserver to watch for inserts?
- }
-
- if (!isCustomTag(localName)) {
- throw new ArgumentError('$localName is not a valid custom element name, '
- 'it should have at least one dash and not be a reserved name.');
- }
-
- if (_customElements.containsKey(localName)) {
- throw new ArgumentError('custom element $localName already registered.');
- }
-
- // TODO(jmesserly): validate this is a valid tag name, not a selector.
- _customElements[localName] = create;
-
- // Initialize elements already on the page.
- for (var query in [localName, '[is=$localName]']) {
- for (var element in document.queryAll(query)) {
- _initCustomElement(element, create);
- }
- }
-}
-
/**
- * Creates a new element and returns it. If the [localName] has been registered
- * with [registerCustomElement], it will create the custom element.
+ * *Deprecated* -- do not use. Extend [HtmlElement] and use
+ * [document.register] instead. If running on a browser without native
+ * document.register, you can add the polyfill script to your page:
*
- * This is similar to `new Element.tag` in Dart and `document.createElement`
- * in JavaScript.
+ * <script src="packages/custom_element/custom-elements.debug.js"></script>
*
- * *Warning*: this API is temporary until [dart:html] supports custom elements.
- */
-Element createElement(String localName) =>
- initCustomElements(new Element.tag(localName));
-
-/**
- * Similar to `new Element.html`, but automatically creates registed custom
- * elements.
- * *Warning*: this API is temporary until [dart:html] supports custom elements.
- */
-Element createElementFromHtml(String html) =>
- initCustomElements(new Element.html(html));
-
-/**
- * Initialize any registered custom elements recursively in the [node] tree.
- * For convenience this returns the [node] instance.
- *
- * *Warning*: this API is temporary until [dart:html] supports custom elements.
- */
-Node initCustomElements(Node node) {
- for (var c = node.firstChild; c != null; c = c.nextNode) {
- initCustomElements(c);
- }
- if (node is Element) {
- var ctor = _customElements[(node as Element).localName];
- if (ctor == null) {
- var attr = (node as Element).attributes['is'];
- if (attr != null) ctor = _customElements[attr];
- }
- if (ctor != null) _initCustomElement(node, ctor);
- }
- return node;
-}
-
-/**
- * The base class for all Dart web components. In addition to the [Element]
- * interface, it also provides lifecycle methods:
- * - [created]
- * - [inserted]
- * - [attributeChanged]
- * - [removed]
+ * You can also use "custom-elements.min.js" for the minified version.
*/
+// This is only used by Dart Web UI.
class CustomElement implements Element {
/** The web component element wrapped by this class. */
Element _host;
@@ -608,47 +529,3 @@ class CustomElement implements Element {
throw new UnsupportedError('onMouseWheel is not supported');
}
}
-
-
-Map<String, Function> _customElements;
-
-void _initCustomElement(Element node, CustomElement ctor()) {
- CustomElement element = ctor();
- element.host = node;
-
- // TODO(jmesserly): replace lifecycle stuff with a proper polyfill.
- element.created();
-
- _registerLifecycleInsert(element);
-}
-
-void _registerLifecycleInsert(CustomElement element) {
- scheduleMicrotask(() {
- // TODO(jmesserly): bottom up or top down insert?
- var node = element.host;
-
- // TODO(jmesserly): need a better check to see if the node has been removed.
- if (node.parentNode == null) return;
-
- _registerLifecycleRemove(element);
- element.inserted();
- });
-}
-
-void _registerLifecycleRemove(CustomElement element) {
- // TODO(jmesserly): need fallback or polyfill for MutationObserver.
- if (!MutationObserver.supported) return;
-
- new MutationObserver((records, observer) {
- var node = element.host;
- for (var record in records) {
- for (var removed in record.removedNodes) {
- if (identical(node, removed)) {
- observer.disconnect();
- element.removed();
- return;
- }
- }
- }
- }).observe(element.parentNode, childList: true);
-}
« no previous file with comments | « no previous file | pkg/custom_element/lib/src/attribute_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698