Last active
March 12, 2016 02:05
-
-
Save shama/25b529a50271e322ff10 to your computer and use it in GitHub Desktop.
morphdom with updating event handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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