| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 library web_components.custom_element_proxy; | 4 library web_components.custom_element_proxy; |
| 5 | 5 |
| 6 import 'dart:js' as js; |
| 6 import 'package:initialize/initialize.dart'; | 7 import 'package:initialize/initialize.dart'; |
| 7 import 'interop.dart'; | 8 import 'interop.dart'; |
| 8 | 9 |
| 9 /// Annotation for a dart class which proxies a javascript custom element. | 10 /// Annotation for a dart class which proxies a javascript custom element. |
| 10 /// This will not work unless `interop_support.js` is loaded. | 11 /// This will not work unless `interop_support.js` is loaded. |
| 11 // TODO(jakemac): Add an @HtmlImport here to a new file which includes | 12 // TODO(jakemac): Add an @HtmlImport here to a new file which includes |
| 12 // `interop_support.js`. We will need to point everything else at that html file | 13 // `interop_support.js`. We will need to point everything else at that html file |
| 13 // as well for deduplication purposes (could even just copy it in as an inline | 14 // as well for deduplication purposes (could even just copy it in as an inline |
| 14 // script so the js file no longer exists?). | 15 // script so the js file no longer exists?). |
| 15 class CustomElementProxy implements Initializer<Type> { | 16 class CustomElementProxy implements Initializer<Type> { |
| 16 final String tagName; | 17 final String tagName; |
| 17 final String extendsTag; | 18 final String extendsTag; |
| 18 | 19 |
| 19 const CustomElementProxy(this.tagName, {this.extendsTag}); | 20 const CustomElementProxy(this.tagName, {this.extendsTag}); |
| 20 | 21 |
| 21 void initialize(Type t) { | 22 void initialize(Type t) { |
| 22 registerDartType(tagName, t, extendsTag: extendsTag); | 23 registerDartType(tagName, t, extendsTag: extendsTag); |
| 23 } | 24 } |
| 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 |