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() seems not to work #643

Closed zoechi closed 8 years ago

zoechi commented 8 years ago

https://github.com/bwu-dart/polymer_elements_demos/blob/6f21c3acdea85b5e7c98494951e23475bc15dd22/web/prism_element/prism_demo.dart#L38

The <prism-highlighter> (in the local DOM) listens for syntax-highlight on the parent (<prism-demo>) but doesn't receive the event. When I add an event handler in <prism-demo> itself, it also doesn't receive the event.

Should this work this way?

jakemac53 commented 8 years ago

There is a basic test here which is passing https://github.com/dart-lang/polymer_interop/blob/1.0.0-rc.5/test/polymer_base_test.dart#L152. Seems like an issue with the element?

zoechi commented 8 years ago

It's often helpful to talk to someone about the problem ;-) I added async(...) and now it's working.

This is the 2nd time I run into this issue. It seems to work in JS but not in Dart when code is run from a property observer. There seems to be some timing difference.

zoechi commented 8 years ago

And thanks for looking into it :+1:

jakemac53 commented 8 years ago

Definitely weird, I will look into this a bit.

jakemac53 commented 8 years ago

Hmm I actually don't see the error? Tried regular server in dartium as well as pub serve in dartium/chrome.

zoechi commented 8 years ago

Now I can't anymore either :disappointed: or better :smile: Maybe it worked all the time, but I have no idea why the breakpoint didn't hit previously, but then with async() it did.

I now run into another issue. Maybe this tricked me into thinking that the event wasn't processed. When I call

var result = fire('syntax-highlight', detail: {'code': code, 'lang': lang});
result.detail['code']

should return the highlighted result but I get the result only with this code

(result as CustomEventWrapper).original.detail['code'];
zoechi commented 8 years ago

Actually I still need async()

zoechi commented 8 years ago

Could this depend on the performance of the used machine? Mine is a bit outdated. It was a powerful notebook once, but is now several years old.

jakemac53 commented 8 years ago

It certainly could, although I would hope its not haha. I think its more likely different dartium versions or something along those lines.

zoechi commented 8 years ago

Ok, I'll monitor it and try to find a way to make it reproducable. What do you think about the detail not being updated on the return value of fire(...)?

jakemac53 commented 8 years ago

What do you think about the detail not being updated on the return value of fire(...)?

Not sure on that one, definitely should work. I can investigate it shortly.

jakemac53 commented 8 years ago

hmm I just tried

var event = fire('my-event', detail: {'foo': 'bar'});
print(event.detail['foo']);

and that printed bar as expected?

zoechi commented 8 years ago

In the demo where I run into this, an event handler updates the detail content, and this updated data is not available (only in event.original.detail). The value I passed to fire() was there, but that's not what's needed.

jakemac53 commented 8 years ago

oh... ya that is just not going to work today :(

jakemac53 commented 8 years ago

been debating this for a while.... but we could just implement a wrapper around JsObject instead of converting them to a Map. That is probably the safer choice but definitely a breaking change. Could do the same for List/JsArray as well.

jakemac53 commented 8 years ago

closing as a dupe of https://github.com/dart-lang/polymer-dart/issues/586