Skip to content

Instantly share code, notes, and snippets.

@shama
Last active March 12, 2016 02:05
Show Gist options
  • Save shama/25b529a50271e322ff10 to your computer and use it in GitHub Desktop.
Save shama/25b529a50271e322ff10 to your computer and use it in GitHub Desktop.
morphdom with updating event handlers
var yo = require('yo-yo')
var orig = yo`<button onclick=${function () {
console.log('orig clicked!')
}}>click</button>`
setTimeout(function () {
var newbutton = yo`<button onclick=${function () {
console.log('new clicked!')
}}>click new</button>`
yo.update(orig, newbutton, {
onBeforeMorphEl: function (fromEl, toEl) {
fromEl.onclick = toEl.onclick
}
})
// or newbutton.onclick = orig.onclick
}, 1000)
document.body.appendChild(orig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment