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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/web_components/lib/dart_support.js ('k') | pkg/web_components/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Provides support for associating a Dart type for Javascript Custom Elements.
6 /// This will not work unless `dart_support.js` is loaded.
7 library web_components.interop;
8
9 import 'dart:async' show Stream, StreamController;
10 import 'dart:html' show document, Element;
11 import 'dart:js' show JsObject, JsFunction;
12
13 final _doc = new JsObject.fromBrowserObject(document);
14
15 /// Returns whether [registerDartType] is supported, which requires to have
16 /// `dart_support.js` already loaded in the page.
17 bool get isSupported => _doc.hasProperty('_registerDartTypeUpgrader');
18
19 /// Watches when Javascript custom elements named [tagName] are created and
20 /// associates the created element with the given [dartType]. Only one Dart type
21 /// can be registered for a given tag name.
22 void registerDartType(String tagName, Type dartType, {String extendsTag}) {
23 if (!isSupported) {
24 throw new UnsupportedError("Couldn't find "
25 "`document._registerDartTypeUpgrader`. Please make sure that "
26 "`packages/web_components/dart_support.js` is loaded and available "
27 "before calling this function.");
28 }
29
30 var upgrader = document.createElementUpgrader(
31 dartType, extendsTag: extendsTag);
32 _doc.callMethod('_registerDartTypeUpgrader', [tagName, upgrader.upgrade]);
33 }
OLDNEW
« 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