Skip to content

Conversation

@betalb
Copy link
Contributor

@betalb betalb commented Feb 12, 2018

Add support for options argument

This PR also fixes handler registration with or without capture flag. Even though useCapture flag is not relevant for XHR object, browsers follow spec in this respect and allow to register 2 handlers if they have different capture flags: see last step in https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener

Copy link
Member

@mroderick mroderick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed pull request 🍦

I only have one minor comment

};
}
return {
capture: !!options.capture,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using !! for implicit type coercion has a few drawbacks

  • it's easy for Future Contributor to make mistakes that do not look wrong at a glance (!, !!, !!!), which means it won't get caught be linters or reviewers
  • it's difficult to understand for newcomers to JavaScript

Would you mind changing the !! to use the Boolean() function instead?

  capture: Boolean(options.capture),

@betalb
Copy link
Contributor Author

betalb commented Feb 28, 2018

Thank you for review @mroderick, no concerns about using Boolean function, updated PR

@mroderick mroderick merged commit f5906bb into sinonjs:master Mar 1, 2018
@mroderick
Copy link
Member

Thank you 👍 This has been published as nise@1.3.0

@fatso83
Copy link
Contributor

fatso83 commented Jun 1, 2018

@betalb We miss documentation for this feature. Any chance you could supply some docs?

@betalb
Copy link
Contributor Author

betalb commented Jun 4, 2018

@fatso83 Sorry, forgot to update, I saw separate ticket, will try to do this asap

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

Successfully merging this pull request may close these issues.

3 participants