Skip to content

Commit

Permalink
Add docs about using EventListener objects (#2260)
Browse files Browse the repository at this point in the history
* Add docs about using EventListener objects

* Fix typo

* Less misleading description of event handlers

* Fix a typo + grammar mistake

* More grammar/typo fixes
  • Loading branch information
spacejack authored and dead-claudia committed Oct 27, 2018
1 parent 86549d3 commit 0e6223d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/hyperscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,29 @@ function doSomething(e) {
m("div", {onclick: doSomething})
```

Mithril accepts functions and [EventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventListener) objects. So this will also work:

```javascript
var clickListener = {
handleEvent: function(e) {
console.log(e)
}
}

m("div", {onclick: clickListener})
```

By default, when an event attached with hyperscript fires, this will trigger Mithril's auto-redraw after your event callback returns (assuming you are using `m.mount` or `m.route` instead of `m.render` directly). You can disable auto-redraw specifically for a single event by setting `e.redraw = false` on it:

```javascript
m("div", {
onclick: function(e) {
// Prevent auto-redraw
e.redraw = false
}
})
```

---

### Properties
Expand Down

0 comments on commit 0e6223d

Please sign in to comment.