dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
181 stars 33 forks source link

`fire()` throws because event is `EventImpl` instead of `CustomEvent` #700

Closed zoechi closed 8 years ago

zoechi commented 8 years ago

Description

Uncaught Unhandled exception: type 'EventImpl' is not a subtype of type 'CustomEvent' of 'e' where EventImpl is from dart:html CustomEvent is from dart:html

Steps to Reproduce

Run the code in this repo https://github.com/bwu-dart-playground/bug_repo/blob/master/event_impl_instead_of_custom_event/web/context_menu.dart#L31

The commented out line fire(...) causes the exception The active line dispatchEvent(...) works fine

Expected Results

`fire()´ to not cause this type conflict

Actual Results

Not sure if it's a bug or a limitation of the way Polymer is wrapped.

jakemac53 commented 8 years ago

Presumably, this is throwing here https://github.com/bwu-dart-playground/bug_repo/blob/master/event_impl_instead_of_custom_event/web/context_menu.dart#L28. The issue afaik is actually that fire does not fire a real CustomEvent (polymer js mimics them). You would need to change that type to just Event, and then call convertToDart(event) to get a CustomEvent.

Or, if you just use @Observe(ContextMenu.contextMenuSelect) annotation on a method then it should be handled for you.

zoechi commented 8 years ago

Thanks for the info! So is this "as designed"? Then the issue can be closed. I changed fire to dispatchEvent. The events are listened to by Dart code only anyway.