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

Unified Diff: pkg/web_components/lib/interop.dart

Issue 319263002: Add "created-watcher" to the web_components package. This was adapted from (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | « pkg/web_components/lib/dart_support.js ('k') | pkg/web_components/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/web_components/lib/interop.dart
diff --git a/pkg/web_components/lib/interop.dart b/pkg/web_components/lib/interop.dart
new file mode 100644
index 0000000000000000000000000000000000000000..058ce76d637cf914d151c9c7a507ea8d413d0aa3
--- /dev/null
+++ b/pkg/web_components/lib/interop.dart
@@ -0,0 +1,33 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Provides support for associating a Dart type for Javascript Custom Elements.
+/// This will not work unless `dart_support.js` is loaded.
+library web_components.interop;
+
+import 'dart:async' show Stream, StreamController;
+import 'dart:html' show document, Element;
+import 'dart:js' show JsObject, JsFunction;
+
+final _doc = new JsObject.fromBrowserObject(document);
+
+/// Returns whether [registerDartType] is supported, which requires to have
+/// `dart_support.js` already loaded in the page.
+bool get isSupported => _doc.hasProperty('_registerDartTypeUpgrader');
+
+/// Watches when Javascript custom elements named [tagName] are created and
+/// associates the created element with the given [dartType]. Only one Dart type
+/// can be registered for a given tag name.
+void registerDartType(String tagName, Type dartType, {String extendsTag}) {
+ if (!isSupported) {
+ throw new UnsupportedError("Couldn't find "
+ "`document._registerDartTypeUpgrader`. Please make sure that "
+ "`packages/web_components/dart_support.js` is loaded and available "
+ "before calling this function.");
+ }
+
+ var upgrader = document.createElementUpgrader(
+ dartType, extendsTag: extendsTag);
+ _doc.callMethod('_registerDartTypeUpgrader', [tagName, upgrader.upgrade]);
+}
« no previous file with comments | « pkg/web_components/lib/dart_support.js ('k') | pkg/web_components/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698