Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fire and asyncFire need return values #527

Closed
esprehn opened this issue Jun 11, 2014 · 4 comments
Closed

fire and asyncFire need return values #527

esprehn opened this issue Jun 11, 2014 · 4 comments
Assignees

Comments

@esprehn
Copy link

esprehn commented Jun 11, 2014

You need a way to detect if an event was cancelled just like the platform does. Normally dispatchEvent() has a return value, and the event has a way to check if the default was prevented. Polymer should expose this value:

if (this.fire("some-event")) {
// do something, the default was not prevented.
}

this.asyncFire("some-event").then(function() {
// do something, the default was not prevented.
});

There's no way to fire an event today and let consumers cancel it which is causing issues in some of my apps where I want to do things like trap all key presses, dispatch a custom event to instances like polymer-signals does, and then only allow the native keypress action to happen if the default is not prevented.

@sjmiles
Copy link
Contributor

sjmiles commented Jun 11, 2014

Please review: http://jsbin.com/wasaguwu/7/edit

@esprehn
Copy link
Author

esprehn commented Jun 13, 2014

Amazing, what about asyncFire?

@sjmiles
Copy link
Contributor

sjmiles commented Jun 13, 2014

It would be better if asyncFire returned a Promise, but we are reluctant to include the Promise polyfill unless we really need it. For now, I would suggest just unrolling it like so:

this.async(function() {
  console.log('async foo prevented: ' + this.fire('foo').defaultPrevented);
});

@sjmiles
Copy link
Contributor

sjmiles commented Jun 13, 2014

Above, I should have said outright that fire returns the event object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants