From bd204a2a3dfd7ec9a1d4e11413df817837f47811 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 22 Jul 2014 14:19:44 -0700 Subject: [PATCH] add noSuchMethod proxying to the js element --- example/core_drawer_panel.html | 4 +-- lib/core_animated_pages.dart | 16 +++++++++++- lib/core_animation.dart | 42 ++++++++++++++++++++++++++++++- lib/core_animation_group.dart | 16 +++++++++++- lib/core_collapse.dart | 16 +++++++++++- lib/core_drag_drop.dart | 16 +++++++++++- lib/core_drawer_panel.dart | 16 +++++++++++- lib/core_field.dart | 16 +++++++++++- lib/core_header_panel.dart | 16 +++++++++++- lib/core_icon.dart | 16 +++++++++++- lib/core_icon_button.dart | 16 +++++++++++- lib/core_icons.dart | 3 ++- lib/core_iconset.dart | 16 +++++++++++- lib/core_iconset_svg.dart | 16 +++++++++++- lib/core_input.dart | 16 +++++++++++- lib/core_item.dart | 16 +++++++++++- lib/core_key_helper.dart | 16 +++++++++++- lib/core_layout_grid.dart | 16 +++++++++++- lib/core_layout_trbl.dart | 16 +++++++++++- lib/core_media_query.dart | 16 +++++++++++- lib/core_menu.dart | 16 +++++++++++- lib/core_menu_button.dart | 16 +++++++++++- lib/core_meta.dart | 16 +++++++++++- lib/core_overlay.dart | 16 +++++++++++- lib/core_overlay_layer.dart | 16 +++++++++++- lib/core_pages.dart | 16 +++++++++++- lib/core_range.dart | 16 +++++++++++- lib/core_scaffold.dart | 16 +++++++++++- lib/core_scroll_header_panel.dart | 16 +++++++++++- lib/core_selection.dart | 16 +++++++++++- lib/core_selector.dart | 16 +++++++++++- lib/core_shared_lib.dart | 16 +++++++++++- lib/core_signals.dart | 16 +++++++++++- lib/core_slide.dart | 16 +++++++++++- lib/core_splitter.dart | 16 +++++++++++- lib/core_style.dart | 16 +++++++++++- lib/core_submenu.dart | 16 +++++++++++- lib/core_toolbar.dart | 16 +++++++++++- lib/core_tooltip.dart | 16 +++++++++++- lib/core_transition.dart | 16 +++++++++++- lib/core_transition_css.dart | 16 +++++++++++- lib/src/codegen.dart | 23 ++++++++++++++++- lib/web_animations.dart | 3 ++- 43 files changed, 638 insertions(+), 45 deletions(-) diff --git a/example/core_drawer_panel.html b/example/core_drawer_panel.html index 8dea659..8b40295 100644 --- a/example/core_drawer_panel.html +++ b/example/core_drawer_panel.html @@ -76,11 +76,9 @@ import 'package:polymer/polymer.dart'; export 'package:polymer/init.dart' show main; - _js(x) => new JsObject.fromBrowserObject(x); - @initMethod init() { querySelector('div[main] > button').onClick.listen((_) { - _js(querySelector('core-drawer-panel')).callMethod('togglePanel'); + querySelector('core-drawer-panel').togglePanel(); }); } diff --git a/lib/core_animated_pages.dart b/lib/core_animated_pages.dart index f743cf3..081e1d3 100644 --- a/lib/core_animated_pages.dart +++ b/lib/core_animated_pages.dart @@ -4,7 +4,8 @@ library core_elements.core_animated_pages; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_selector.dart'; @@ -223,6 +224,19 @@ class CoreAnimatedPages extends CoreSelector { /// on incoming and outgoing pages. get lastSelected => jsElement['lastSelected']; set lastSelected(value) { jsElement['lastSelected'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreAnimatedPages() => registerDartType('core-animated-pages', CoreAnimatedPages); diff --git a/lib/core_animation.dart b/lib/core_animation.dart index da8b79f..df92fda 100644 --- a/lib/core_animation.dart +++ b/lib/core_animation.dart @@ -4,7 +4,8 @@ library core_elements.core_animation; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -200,6 +201,19 @@ class CoreAnimation extends HtmlElement with DomProxyMixin { /// plays it if autoplay is true. apply() => jsElement.callMethod('apply', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreAnimation() => registerDartType('core-animation', CoreAnimation); @@ -219,6 +233,19 @@ class CoreAnimationKeyframe extends HtmlElement with DomProxyMixin { set offset(value) { jsElement['offset'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} get properties => jsElement['properties']; + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreAnimationKeyframe() => registerDartType('core-animation-keyframe', CoreAnimationKeyframe); @@ -237,6 +264,19 @@ class CoreAnimationProp extends HtmlElement with DomProxyMixin { /// The value for the CSS property. get value => jsElement['value']; set value(value) { jsElement['value'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreAnimationProp() => registerDartType('core-animation-prop', CoreAnimationProp); diff --git a/lib/core_animation_group.dart b/lib/core_animation_group.dart index 09f9f76..d78af80 100644 --- a/lib/core_animation_group.dart +++ b/lib/core_animation_group.dart @@ -4,7 +4,8 @@ library core_elements.core_animation_group; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_animation.dart'; @@ -54,6 +55,19 @@ class CoreAnimationGroup extends CoreAnimation { get childAnimationElements => jsElement['childAnimationElements']; get childAnimations => jsElement['childAnimations']; + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreAnimationGroup() => registerDartType('core-animation-group', CoreAnimationGroup); diff --git a/lib/core_collapse.dart b/lib/core_collapse.dart index fc50f33..d377edd 100644 --- a/lib/core_collapse.dart +++ b/lib/core_collapse.dart @@ -4,7 +4,8 @@ library core_elements.core_collapse; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -52,6 +53,19 @@ class CoreCollapse extends HtmlElement with DomProxyMixin { /// Toggle the opened state. void toggle() => jsElement.callMethod('toggle', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreCollapse() => registerDartType('core-collapse', CoreCollapse); diff --git a/lib/core_drag_drop.dart b/lib/core_drag_drop.dart index 2e98e9e..5a1a947 100644 --- a/lib/core_drag_drop.dart +++ b/lib/core_drag_drop.dart @@ -4,7 +4,8 @@ library core_elements.core_drag_drop; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -12,6 +13,19 @@ import 'package:core_elements/src/common.dart' show DomProxyMixin; class CoreDragDrop extends HtmlElement with DomProxyMixin { CoreDragDrop.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreDragDrop() => registerDartType('core-drag-drop', CoreDragDrop); diff --git a/lib/core_drawer_panel.dart b/lib/core_drawer_panel.dart index 9521e8e..52fa706 100644 --- a/lib/core_drawer_panel.dart +++ b/lib/core_drawer_panel.dart @@ -4,7 +4,8 @@ library core_elements.core_drawer_panel; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -53,6 +54,19 @@ class CoreDrawerPanel extends HtmlElement with DomProxyMixin { /// need to show/hide elements based on the layout. bool get narrow => jsElement['narrow']; set narrow(bool value) { jsElement['narrow'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreDrawerPanel() => registerDartType('core-drawer-panel', CoreDrawerPanel); diff --git a/lib/core_field.dart b/lib/core_field.dart index 5ad12ed..b64dd79 100644 --- a/lib/core_field.dart +++ b/lib/core_field.dart @@ -4,7 +4,8 @@ library core_elements.core_field; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -20,6 +21,19 @@ import 'package:core_elements/src/common.dart' show DomProxyMixin; /// class CoreField extends HtmlElement with DomProxyMixin { CoreField.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreField() => registerDartType('core-field', CoreField); diff --git a/lib/core_header_panel.dart b/lib/core_header_panel.dart index b0e256d..65ae5dd 100644 --- a/lib/core_header_panel.dart +++ b/lib/core_header_panel.dart @@ -4,7 +4,8 @@ library core_elements.core_header_panel; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -112,6 +113,19 @@ class CoreHeaderPanel extends HtmlElement with DomProxyMixin { get header => jsElement['header']; get scroller => jsElement['scroller']; + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreHeaderPanel() => registerDartType('core-header-panel', CoreHeaderPanel); diff --git a/lib/core_icon.dart b/lib/core_icon.dart index 0756a38..4dfac2c 100644 --- a/lib/core_icon.dart +++ b/lib/core_icon.dart @@ -4,7 +4,8 @@ library core_elements.core_icon; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -48,6 +49,19 @@ class CoreIcon extends HtmlElement with DomProxyMixin { /// the src property should not be. String get icon => jsElement['icon']; set icon(String value) { jsElement['icon'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreIcon() => registerDartType('core-icon', CoreIcon); diff --git a/lib/core_icon_button.dart b/lib/core_icon_button.dart index d7cd3ce..86a8ede 100644 --- a/lib/core_icon_button.dart +++ b/lib/core_icon_button.dart @@ -4,7 +4,8 @@ library core_elements.core_icon_button; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -38,6 +39,19 @@ class CoreIconButton extends HtmlElement with DomProxyMixin { /// active state. bool get active => jsElement['active']; set active(bool value) { jsElement['active'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreIconButton() => registerDartType('core-icon-button', CoreIconButton); diff --git a/lib/core_icons.dart b/lib/core_icons.dart index 8d2d34e..f693533 100644 --- a/lib/core_icons.dart +++ b/lib/core_icons.dart @@ -4,7 +4,8 @@ library core_elements.core_icons; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; diff --git a/lib/core_iconset.dart b/lib/core_iconset.dart index d8f1bf1..395ad80 100644 --- a/lib/core_iconset.dart +++ b/lib/core_iconset.dart @@ -4,7 +4,8 @@ library core_elements.core_iconset; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_meta.dart'; @@ -109,6 +110,19 @@ class CoreIconset extends CoreMeta { /// with which the icon can be magnified. void applyIcon(element,icon,String theme,scale) => jsElement.callMethod('applyIcon', [element,icon,theme,scale]); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreIconset() => registerDartType('core-iconset', CoreIconset); diff --git a/lib/core_iconset_svg.dart b/lib/core_iconset_svg.dart index d6e3422..a2e4dcc 100644 --- a/lib/core_iconset_svg.dart +++ b/lib/core_iconset_svg.dart @@ -4,7 +4,8 @@ library core_elements.core_iconset_svg; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_meta.dart'; @@ -64,6 +65,19 @@ class CoreIconsetSvg extends CoreMeta { /// defaults to 'updateIcon' void updateIcons(String css,String method) => jsElement.callMethod('updateIcons', [css,method]); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreIconsetSvg() => registerDartType('core-iconset-svg', CoreIconsetSvg); diff --git a/lib/core_input.dart b/lib/core_input.dart index 1bd7b0d..2e4ae8a 100644 --- a/lib/core_input.dart +++ b/lib/core_input.dart @@ -4,7 +4,8 @@ library core_elements.core_input; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -119,6 +120,19 @@ class CoreInput extends HtmlElement with DomProxyMixin { /// Commits the inputValue to value. void commit() => jsElement.callMethod('commit', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreInput() => registerDartType('core-input', CoreInput); diff --git a/lib/core_item.dart b/lib/core_item.dart index 9114bac..0fcbf38 100644 --- a/lib/core_item.dart +++ b/lib/core_item.dart @@ -4,7 +4,8 @@ library core_elements.core_item; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -41,6 +42,19 @@ class CoreItem extends HtmlElement with DomProxyMixin { /// Specifies the size of the icon in pixel units. num get size => jsElement['size']; set size(num value) { jsElement['size'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreItem() => registerDartType('core-item', CoreItem); diff --git a/lib/core_key_helper.dart b/lib/core_key_helper.dart index bfb7d3d..4fd5674 100644 --- a/lib/core_key_helper.dart +++ b/lib/core_key_helper.dart @@ -4,7 +4,8 @@ library core_elements.core_key_helper; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -12,6 +13,19 @@ import 'package:core_elements/src/common.dart' show DomProxyMixin; class CoreKeyHelper extends HtmlElement with DomProxyMixin { CoreKeyHelper.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreKeyHelper() => registerDartType('core-key-helper', CoreKeyHelper); diff --git a/lib/core_layout_grid.dart b/lib/core_layout_grid.dart index dc12fee..472c8a7 100644 --- a/lib/core_layout_grid.dart +++ b/lib/core_layout_grid.dart @@ -4,7 +4,8 @@ library core_elements.core_layout_grid; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -21,6 +22,19 @@ class CoreLayoutGrid extends HtmlElement with DomProxyMixin { get auto => jsElement['auto']; set auto(value) { jsElement['auto'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreLayoutGrid() => registerDartType('core-layout-grid', CoreLayoutGrid); diff --git a/lib/core_layout_trbl.dart b/lib/core_layout_trbl.dart index 5d5eada..040854c 100644 --- a/lib/core_layout_trbl.dart +++ b/lib/core_layout_trbl.dart @@ -4,7 +4,8 @@ library core_elements.core_layout_trbl; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -130,6 +131,19 @@ class CoreLayoutTrbl extends HtmlElement with DomProxyMixin { /// attribute is applied on this node. void layout() => jsElement.callMethod('layout', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreLayoutTrbl() => registerDartType('core-layout-trbl', CoreLayoutTrbl); diff --git a/lib/core_media_query.dart b/lib/core_media_query.dart index 5d932d3..9eadadb 100644 --- a/lib/core_media_query.dart +++ b/lib/core_media_query.dart @@ -4,7 +4,8 @@ library core_elements.core_media_query; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -33,6 +34,19 @@ class CoreMediaQuery extends HtmlElement with DomProxyMixin { /// The Boolean return value of the media query bool get queryMatches => jsElement['queryMatches']; set queryMatches(bool value) { jsElement['queryMatches'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreMediaQuery() => registerDartType('core-media-query', CoreMediaQuery); diff --git a/lib/core_menu.dart b/lib/core_menu.dart index af734da..6e9aa51 100644 --- a/lib/core_menu.dart +++ b/lib/core_menu.dart @@ -4,7 +4,8 @@ library core_elements.core_menu; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_selector.dart'; @@ -52,6 +53,19 @@ import 'core_selector.dart'; /// } class CoreMenu extends CoreSelector { CoreMenu.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreMenu() => registerDartType('core-menu', CoreMenu); diff --git a/lib/core_menu_button.dart b/lib/core_menu_button.dart index eb1dbfe..cabb3f2 100644 --- a/lib/core_menu_button.dart +++ b/lib/core_menu_button.dart @@ -4,7 +4,8 @@ library core_elements.core_menu_button; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -70,6 +71,19 @@ class CoreMenuButton extends HtmlElement with DomProxyMixin { /// Toggle the opened state of the dropdown. void toggle() => jsElement.callMethod('toggle', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreMenuButton() => registerDartType('core-menu-button', CoreMenuButton); diff --git a/lib/core_meta.dart b/lib/core_meta.dart index 98543b4..c3e33f7 100644 --- a/lib/core_meta.dart +++ b/lib/core_meta.dart @@ -4,7 +4,8 @@ library core_elements.core_meta; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -72,6 +73,19 @@ class CoreMeta extends HtmlElement with DomProxyMixin { /// [id]: The ID of the meta-data to be returned. byId(String id) => jsElement.callMethod('byId', [id]); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreMeta() => registerDartType('core-meta', CoreMeta); diff --git a/lib/core_overlay.dart b/lib/core_overlay.dart index db54d20..571725a 100644 --- a/lib/core_overlay.dart +++ b/lib/core_overlay.dart @@ -4,7 +4,8 @@ library core_elements.core_overlay; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -134,6 +135,19 @@ class CoreOverlay extends HtmlElement with DomProxyMixin { /// browser window resizes. void resizeHandler() => jsElement.callMethod('resizeHandler', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreOverlay() => registerDartType('core-overlay', CoreOverlay); diff --git a/lib/core_overlay_layer.dart b/lib/core_overlay_layer.dart index 0fbe928..dd8b110 100644 --- a/lib/core_overlay_layer.dart +++ b/lib/core_overlay_layer.dart @@ -4,7 +4,8 @@ library core_elements.core_overlay_layer; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -12,6 +13,19 @@ import 'package:core_elements/src/common.dart' show DomProxyMixin; class CoreOverlayLayer extends HtmlElement with DomProxyMixin { CoreOverlayLayer.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreOverlayLayer() => registerDartType('core-overlay-layer', CoreOverlayLayer); diff --git a/lib/core_pages.dart b/lib/core_pages.dart index 479f7fd..133c229 100644 --- a/lib/core_pages.dart +++ b/lib/core_pages.dart @@ -4,7 +4,8 @@ library core_elements.core_pages; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_selector.dart'; @@ -27,6 +28,19 @@ import 'core_selector.dart'; /// class CorePages extends CoreSelector { CorePages.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCorePages() => registerDartType('core-pages', CorePages); diff --git a/lib/core_range.dart b/lib/core_range.dart index 67c320b..bbdfece 100644 --- a/lib/core_range.dart +++ b/lib/core_range.dart @@ -4,7 +4,8 @@ library core_elements.core_range; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -39,6 +40,19 @@ class CoreRange extends HtmlElement with DomProxyMixin { /// Returns the ratio of the value. num get ratio => jsElement['ratio']; set ratio(num value) { jsElement['ratio'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreRange() => registerDartType('core-range', CoreRange); diff --git a/lib/core_scaffold.dart b/lib/core_scaffold.dart index ca97e93..5ed29d2 100644 --- a/lib/core_scaffold.dart +++ b/lib/core_scaffold.dart @@ -4,7 +4,8 @@ library core_elements.core_scaffold; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -53,6 +54,19 @@ class CoreScaffold extends HtmlElement with DomProxyMixin { /// Close the drawer panel void closeDrawer() => jsElement.callMethod('closeDrawer', []); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreScaffold() => registerDartType('core-scaffold', CoreScaffold); diff --git a/lib/core_scroll_header_panel.dart b/lib/core_scroll_header_panel.dart index 68571de..fc0dd73 100644 --- a/lib/core_scroll_header_panel.dart +++ b/lib/core_scroll_header_panel.dart @@ -4,7 +4,8 @@ library core_elements.core_scroll_header_panel; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -64,6 +65,19 @@ class CoreScrollHeaderPanel extends HtmlElement with DomProxyMixin { get header => jsElement['header']; get scroller => jsElement['scroller']; + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreScrollHeaderPanel() => registerDartType('core-scroll-header-panel', CoreScrollHeaderPanel); diff --git a/lib/core_selection.dart b/lib/core_selection.dart index 6edeef1..71869fb 100644 --- a/lib/core_selection.dart +++ b/lib/core_selection.dart @@ -4,7 +4,8 @@ library core_elements.core_selection; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -83,6 +84,19 @@ class CoreSelection extends HtmlElement with DomProxyMixin { /// [item]: The item to toggle. void toggle(item) => jsElement.callMethod('toggle', [item]); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSelection() => registerDartType('core-selection', CoreSelection); diff --git a/lib/core_selector.dart b/lib/core_selector.dart index 6a90be6..3926e5b 100644 --- a/lib/core_selector.dart +++ b/lib/core_selector.dart @@ -4,7 +4,8 @@ library core_elements.core_selector; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -140,6 +141,19 @@ class CoreSelector extends HtmlElement with DomProxyMixin { get items => jsElement['items']; get selection => jsElement['selection']; + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSelector() => registerDartType('core-selector', CoreSelector); diff --git a/lib/core_shared_lib.dart b/lib/core_shared_lib.dart index 77829bd..f57fbb5 100644 --- a/lib/core_shared_lib.dart +++ b/lib/core_shared_lib.dart @@ -4,7 +4,8 @@ library core_elements.core_shared_lib; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -37,6 +38,19 @@ class CoreSharedLib extends HtmlElement with DomProxyMixin { get callbackName => jsElement['callbackName']; set callbackName(value) { jsElement['callbackName'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSharedLib() => registerDartType('core-shared-lib', CoreSharedLib); diff --git a/lib/core_signals.dart b/lib/core_signals.dart index 26e761f..f83284f 100644 --- a/lib/core_signals.dart +++ b/lib/core_signals.dart @@ -4,7 +4,8 @@ library core_elements.core_signals; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -30,6 +31,19 @@ import 'package:core_elements/src/common.dart' show DomProxyMixin; /// of where they are in DOM. class CoreSignals extends HtmlElement with DomProxyMixin { CoreSignals.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSignals() => registerDartType('core-signals', CoreSignals); diff --git a/lib/core_slide.dart b/lib/core_slide.dart index e7439da..ef73047 100644 --- a/lib/core_slide.dart +++ b/lib/core_slide.dart @@ -4,7 +4,8 @@ library core_elements.core_slide; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -27,6 +28,19 @@ class CoreSlide extends HtmlElement with DomProxyMixin { get targetId => jsElement['targetId']; set targetId(value) { jsElement['targetId'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSlide() => registerDartType('core-slide', CoreSlide); diff --git a/lib/core_splitter.dart b/lib/core_splitter.dart index 6c1fab9..da41d89 100644 --- a/lib/core_splitter.dart +++ b/lib/core_splitter.dart @@ -4,7 +4,8 @@ library core_elements.core_splitter; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -60,6 +61,19 @@ class CoreSplitter extends HtmlElement with DomProxyMixin { /// Disables the selection of text while the splitter is being moved get disableSelection => jsElement['disableSelection']; set disableSelection(value) { jsElement['disableSelection'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSplitter() => registerDartType('core-splitter', CoreSplitter); diff --git a/lib/core_style.dart b/lib/core_style.dart index 51d6bf4..dc8a156 100644 --- a/lib/core_style.dart +++ b/lib/core_style.dart @@ -4,7 +4,8 @@ library core_elements.core_style; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -109,6 +110,19 @@ class CoreStyle extends HtmlElement with DomProxyMixin { /// inside another. get list => jsElement['list']; set list(value) { jsElement['list'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreStyle() => registerDartType('core-style', CoreStyle); diff --git a/lib/core_submenu.dart b/lib/core_submenu.dart index eabbe4d..dd9931e 100644 --- a/lib/core_submenu.dart +++ b/lib/core_submenu.dart @@ -4,7 +4,8 @@ library core_elements.core_submenu; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -54,6 +55,19 @@ class CoreSubmenu extends HtmlElement with DomProxyMixin { set valueattr(value) { jsElement['valueattr'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} get items => jsElement['items']; + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreSubmenu() => registerDartType('core-submenu', CoreSubmenu); diff --git a/lib/core_toolbar.dart b/lib/core_toolbar.dart index c5f788b..2d829c7 100644 --- a/lib/core_toolbar.dart +++ b/lib/core_toolbar.dart @@ -4,7 +4,8 @@ library core_elements.core_toolbar; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -48,6 +49,19 @@ import 'package:core_elements/src/common.dart' show DomProxyMixin; /// class CoreToolbar extends HtmlElement with DomProxyMixin { CoreToolbar.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreToolbar() => registerDartType('core-toolbar', CoreToolbar); diff --git a/lib/core_tooltip.dart b/lib/core_tooltip.dart index 2e6217b..29f72e2 100644 --- a/lib/core_tooltip.dart +++ b/lib/core_tooltip.dart @@ -4,7 +4,8 @@ library core_elements.core_tooltip; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'package:core_elements/src/common.dart' show DomProxyMixin; @@ -61,6 +62,19 @@ class CoreTooltip extends HtmlElement with DomProxyMixin { /// If true, the tooltip displays by default. bool get show => jsElement['show']; set show(bool value) { jsElement['show'] = value; } + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreTooltip() => registerDartType('core-tooltip', CoreTooltip); diff --git a/lib/core_transition.dart b/lib/core_transition.dart index 57ce66a..540aad1 100644 --- a/lib/core_transition.dart +++ b/lib/core_transition.dart @@ -4,7 +4,8 @@ library core_elements.core_transition; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_meta.dart'; @@ -12,6 +13,19 @@ import 'core_meta.dart'; class CoreTransition extends CoreMeta { CoreTransition.created() : super.created(); + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreTransition() => registerDartType('core-transition', CoreTransition); diff --git a/lib/core_transition_css.dart b/lib/core_transition_css.dart index 3111f67..2bb2ea7 100644 --- a/lib/core_transition_css.dart +++ b/lib/core_transition_css.dart @@ -4,7 +4,8 @@ library core_elements.core_transition_css; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; import 'core_transition.dart'; @@ -15,6 +16,19 @@ class CoreTransitionCss extends CoreTransition { get transitionType => jsElement['transitionType']; set transitionType(value) { jsElement['transitionType'] = (value is Map || value is Iterable) ? new JsObject.jsify(value) : value;} + + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call ${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + } } @initMethod upgradeCoreTransitionCss() => registerDartType('core-transition-css', CoreTransitionCss); diff --git a/lib/src/codegen.dart b/lib/src/codegen.dart index 0552a3e..c393b56 100644 --- a/lib/src/codegen.dart +++ b/lib/src/codegen.dart @@ -18,8 +18,10 @@ String generateClass(Element element, FileConfig config) { var getDartName = _substituteFunction(config.nameSubstitutions); element.properties.values.forEach((p) => _generateProperty(p, sb, getDartName)); element.methods.forEach((m) => _generateMethod(m, sb, getDartName)); + sb.write(_noSuchMethodFallback); sb.write('}\n'); sb.write(_generateUpdateMethod(element.name)); + return sb.toString(); } @@ -121,7 +123,8 @@ String generateDirectives(String name, Iterable extendNames, library core_elements.$libName; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod; ${extraImports.join('\n')} @@ -187,3 +190,21 @@ final _docToDartType = { 'Object': null, // keep as dynamic 'any': null, // keep as dynamic }; + +// Fallback to pass through unrecognized method calls to the jsElement using +// noSuchMethod. This isn't ideal but it enables functionality that would have +// previously been missing. A print has been added to try and ensure that we +// still have bug reports filed on us for missing methods. +final _noSuchMethodFallback = '''\n + noSuchMethod(Invocation invocation) { + String methodName = MirrorSystem.getName(invocation.memberName); + if (invocation.isMethod && jsElement[methodName] is JsFunction) { + print('Warning, passing missing method call \${methodName} to ' + 'JS element. This may impact performance, and should be wrapped ' + 'explicitely in dart.'); + jsElement.callMethod( + methodName, invocation.positionalArguments); + } else { + super.noSuchMethod(invocation); + } + }\n'''; \ No newline at end of file diff --git a/lib/web_animations.dart b/lib/web_animations.dart index 1361037..5cc89b2 100644 --- a/lib/web_animations.dart +++ b/lib/web_animations.dart @@ -4,7 +4,8 @@ library core_elements.web_animations; import 'dart:html'; -import 'dart:js' show JsArray, JsObject; +import 'dart:js' show JsArray, JsObject, JsFunction; +import 'dart:mirrors'; import 'package:web_components/interop.dart' show registerDartType; import 'package:polymer/polymer.dart' show initMethod;