OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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 library web_components.custom_element_proxy; | |
5 | |
6 import 'dart:js' as js; | |
7 import 'package:initialize/initialize.dart'; | |
8 import 'interop.dart'; | |
9 | |
10 /// Annotation for a dart class which proxies a javascript custom element. | |
11 /// This will not work unless `interop_support.js` is loaded. | |
12 // TODO(jakemac): Add an @HtmlImport here to a new file which includes | |
13 // `interop_support.js`. We will need to point everything else at that html file | |
14 // as well for deduplication purposes (could even just copy it in as an inline | |
15 // script so the js file no longer exists?). | |
16 class CustomElementProxy implements Initializer<Type> { | |
17 final String tagName; | |
18 final String extendsTag; | |
19 | |
20 const CustomElementProxy(this.tagName, {this.extendsTag}); | |
21 | |
22 void initialize(Type t) { | |
23 registerDartType(tagName, t, extendsTag: extendsTag); | |
24 } | |
25 } | |
26 | |
27 /// A simple mixin to make it easier to interoperate with the Javascript API of | |
28 /// a browser object. This is mainly used by classes that expose a Dart API for | |
29 /// Javascript custom elements. | |
30 class CustomElementProxyMixin { | |
31 js.JsObject _proxy; | |
32 | |
33 js.JsObject get jsElement { | |
34 if (_proxy == null) { | |
35 _proxy = new js.JsObject.fromBrowserObject(this); | |
36 } | |
37 return _proxy; | |
38 } | |
39 } | |
OLD | NEW |