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

Add docs about using EventListener objects #2260

Merged
merged 5 commits into from
Oct 27, 2018

Conversation

spacejack
Copy link
Contributor

Description

Added notes about using EventListener objects, as well as preventing auto-redraw.

Motivation and Context

Document new features in v2, add needed docs for redraw prevention.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation change

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated docs/change-log.md

@@ -278,6 +278,29 @@ function doSomething(e) {
m("div", {onclick: doSomething})
```

Mithril adds event listeners to the DOM using [EventTarget#addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener). This means you can provide a function (as above) or an [EventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventListener) object. For example:
Copy link
Member

Choose a reason for hiding this comment

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

That's not how it works internally, and I'd rather not give people a false impression on that. You could still mention that both functions and event listener objects work, just don't include the implementation detail that gives people the wrong impression, especially of performance implications. (Changing existing listeners is a simple object property write, not a removeEventListener + addEventListener pair.)

docs/hyperscript.md Show resolved Hide resolved
@dead-claudia
Copy link
Member

I made some minor grammar/typo fixes to the patch. Apart from that, looks good to me. 👍

@dead-claudia dead-claudia merged commit 0e6223d into MithrilJS:next Oct 27, 2018
@spacejack spacejack deleted the docs-events branch October 28, 2018 19:43
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