Hi,
I'm trying to write a simple proof of concept.
I would like to virtualize an existing DOM node, generate a new VTree with h
, then diff the two and patch the DOM node.
What I do is:
var vtree = h('div', null, [
h('button', {onclick: onClick}, 'Modify')
, h('div.vdom-content', null, [])
])
, rootNode = createElement(vtree)
node.appendChild(rootNode)
and then, when the button is clicked, I select the .vdom-content
element and pass it to the view function:
function render() {
return h('div.vdom-content', null, [])
}
function view(node) {
var oldVtree = virtualize(node)
, newVtree = render()
, patches = diff(oldVtree, newVtree)
patch(node, patches)
}
This results in the vdom-content
class in my patch being removed, which is quite surprising. The only difference between the oldVtree and the newVtree is that oldVtree, generated by virtualize, has the properties.attributes object, and newVtree does not:
attributes: { class: "vdom-content" }
They both have properties.className
, set as vdom-content
.
The calculated patches object looks like this:
Is this expected? Obviously I would like to be able to correctly diff between virtualizd nodes and virtual nodes.
I'll post this same issue on the virtual-dom board, because I don't know where the problem is.