Add docs about using EventListener objects (#2260)
* Add docs about using EventListener objects * Fix typo * Less misleading description of event handlers * Fix a typo + grammar mistake * More grammar/typo fixes
This commit is contained in:
parent
86549d3d48
commit
0e6223da73
1 changed files with 23 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue