Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-claudia committed Mar 16, 2020
1 parent 39f6fa9 commit 455e511
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ module.exports = function($window) {
//event
function updateEvent(vnode, key, value) {
if (vnode.events != null) {
vnode.events._ = currentRedraw
if (vnode.events[key] === value) return
if (value != null && (typeof value === "function" || typeof value === "object")) {
if (vnode.events[key] == null) vnode.dom.addEventListener(key.slice(2), vnode.events, false)
Expand Down
34 changes: 31 additions & 3 deletions render/tests/test-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ var domMock = require("../../test-utils/domMock")
var vdom = require("../../render/render")

o.spec("event", function() {
var $window, root, redraw, render
var $window, root, redraw, render, reallyRender
o.beforeEach(function() {
$window = domMock()
root = $window.document.body
redraw = o.spy()
var renderer = vdom($window)
reallyRender = vdom($window)
render = function(dom, vnode) {
return renderer(dom, vnode, redraw)
return reallyRender(dom, vnode, redraw)
}
})

Expand Down Expand Up @@ -355,4 +355,32 @@ o.spec("event", function() {
o(redraw.this).equals(undefined)
o(redraw.args.length).equals(0)
})

o("handles changed spy", function() {
var div1 = {tag: "div", attrs: {ontransitionend: function() {}}}

reallyRender(root, [div1], redraw)
var e = $window.document.createEvent("HTMLEvents")
e.initEvent("transitionend", true, true)
div1.dom.dispatchEvent(e)

o(redraw.callCount).equals(1)
o(redraw.this).equals(undefined)
o(redraw.args.length).equals(0)

var replacementRedraw = o.spy()
var div2 = {tag: "div", attrs: {ontransitionend: function() {}}}

reallyRender(root, [div2], replacementRedraw)
var e = $window.document.createEvent("HTMLEvents")
e.initEvent("transitionend", true, true)
div2.dom.dispatchEvent(e)

o(redraw.callCount).equals(1)
o(redraw.this).equals(undefined)
o(redraw.args.length).equals(0)
o(replacementRedraw.callCount).equals(1)
o(replacementRedraw.this).equals(undefined)
o(replacementRedraw.args.length).equals(0)
})
})

0 comments on commit 455e511

Please sign in to comment.