callum / morphdom-hooks

17 stars 2 forks source link

hooks not getting called #3

Closed SilentCicero closed 8 years ago

SilentCicero commented 8 years ago

Things doesn't seem to fly:

var yo = require("yo-yo")
var hooks = require("morphdom-hooks")
var update = hooks(yo.update)

var app = yo`<div>One</div>`
var app2 = yo`<div>Two!</div>`

app.onupdate = function(node){
  console.log(node);
}

update(app, app2);

document.body.appendChild(app)
callum commented 8 years ago

This is because onupdate isn't set on app2. Hooks are removed like any other property if they don't exist on the element being morphed to. Try:

var yo = require("yo-yo")
var hooks = require("morphdom-hooks")
var update = hooks(yo.update)

var app = yo`<div>One</div>`
var app2 = yo`<div>Two!</div>`

app.onupdate = onupdate
app2.onupdate = onupdate

update(app, app2)

document.body.appendChild(app)

function onupdate (node) {
  console.log(node)
}