Merge pull request #1824 from lhorie/revert-1796-vnode-event
Revert "Pass `vnode` as second argument"
This commit is contained in:
commit
2aa6adf440
3 changed files with 2 additions and 37 deletions
|
|
@ -181,7 +181,7 @@ Mithril does not attempt to add units to number values.
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
Mithril supports event handler binding for all DOM events, using `addEventListener` under the hood to add events in case they don't have a corresponding `on${event}` property, such as the native `touchstart` or third-party events like Bootstrap's `show.bs.modal`.
|
Mithril supports event handler binding for all DOM events, including events whose specs do not define an `on${event}` property, such as `touchstart`
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
function doSomething(e) {
|
function doSomething(e) {
|
||||||
|
|
@ -191,38 +191,6 @@ function doSomething(e) {
|
||||||
m("div", {onclick: doSomething})
|
m("div", {onclick: doSomething})
|
||||||
```
|
```
|
||||||
|
|
||||||
You may access the element itself through `this` like so, which is useful for things like form validation:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function submit(e) {
|
|
||||||
this.validate()
|
|
||||||
m.request("api/form-endpoint", {
|
|
||||||
method: "POST",
|
|
||||||
data: new FormData(this),
|
|
||||||
background: true
|
|
||||||
})
|
|
||||||
.then(function () {
|
|
||||||
m.route.set("/form-submit")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
m("form", {onsubmit: submit}, [
|
|
||||||
// ...
|
|
||||||
])
|
|
||||||
```
|
|
||||||
|
|
||||||
It also provides access to the event's own literal vnode via `vnode`, so you may easily access its `attrs` and `children` through it, from an external function.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
function handleClick(e, vnode) {
|
|
||||||
vnode.attrs.context.validateValue(this.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
m("div", [
|
|
||||||
m("input", {type: "text", context: this, onclick: handleClick})
|
|
||||||
])
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Properties
|
### Properties
|
||||||
|
|
|
||||||
|
|
@ -558,7 +558,7 @@ module.exports = function($window) {
|
||||||
function updateEvent(vnode, key, value) {
|
function updateEvent(vnode, key, value) {
|
||||||
var element = vnode.dom
|
var element = vnode.dom
|
||||||
var callback = typeof onevent !== "function" ? value : function(e) {
|
var callback = typeof onevent !== "function" ? value : function(e) {
|
||||||
var result = value.call(element, e, vnode)
|
var result = value.call(element, e)
|
||||||
onevent.call(element, e)
|
onevent.call(element, e)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ o.spec("event", function() {
|
||||||
o(spy.this).equals(div.dom)
|
o(spy.this).equals(div.dom)
|
||||||
o(spy.args[0].type).equals("click")
|
o(spy.args[0].type).equals("click")
|
||||||
o(spy.args[0].target).equals(div.dom)
|
o(spy.args[0].target).equals(div.dom)
|
||||||
o(spy.args[1]).equals(div)
|
|
||||||
o(onevent.callCount).equals(1)
|
o(onevent.callCount).equals(1)
|
||||||
o(onevent.this).equals(div.dom)
|
o(onevent.this).equals(div.dom)
|
||||||
o(onevent.args[0].type).equals("click")
|
o(onevent.args[0].type).equals("click")
|
||||||
|
|
@ -65,7 +64,6 @@ o.spec("event", function() {
|
||||||
o(spy.this).equals(div.dom)
|
o(spy.this).equals(div.dom)
|
||||||
o(spy.args[0].type).equals("click")
|
o(spy.args[0].type).equals("click")
|
||||||
o(spy.args[0].target).equals(div.dom)
|
o(spy.args[0].target).equals(div.dom)
|
||||||
o(spy.args[1]).equals(div)
|
|
||||||
o(onevent.callCount).equals(1)
|
o(onevent.callCount).equals(1)
|
||||||
o(onevent.this).equals(div.dom)
|
o(onevent.this).equals(div.dom)
|
||||||
o(onevent.args[0].type).equals("click")
|
o(onevent.args[0].type).equals("click")
|
||||||
|
|
@ -87,7 +85,6 @@ o.spec("event", function() {
|
||||||
o(spy.this).equals(div.dom)
|
o(spy.this).equals(div.dom)
|
||||||
o(spy.args[0].type).equals("transitionend")
|
o(spy.args[0].type).equals("transitionend")
|
||||||
o(spy.args[0].target).equals(div.dom)
|
o(spy.args[0].target).equals(div.dom)
|
||||||
o(spy.args[1]).equals(div)
|
|
||||||
o(onevent.callCount).equals(1)
|
o(onevent.callCount).equals(1)
|
||||||
o(onevent.this).equals(div.dom)
|
o(onevent.this).equals(div.dom)
|
||||||
o(onevent.args[0].type).equals("transitionend")
|
o(onevent.args[0].type).equals("transitionend")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue