Open wavesoft opened 4 years ago
Regarding this bit...
First of all, if this expression is running, don't we already know that the key didn't match, and thus the DOM node must be new?
Secondly, it looks like _prevnode
isn't the "previous node", as I first thought - it looks like this is actually the "previous vnode", so if _prevnode
did evaluate as truthy, you would actually end up passing a vnode object, rather than a DOM node, to insertBefore
, which wouldn't work.
My suspicioun is that _vnode
always evaluates as falsy and the second expression after the ||
operator always executes - so I think you can actually just delete the _prevnode ||
part of the expression.
Am I wrong??
Not true.
1) _prevnode
is the previous DOM element. It will be falsy
in any of the following conditions:
2) Note that a few properties from the VDom element are copied onto the DOM element in order to save some space by not carrying around the state variables. These are assigned here and defined here. That's why some time it's confusing to find out which is a DOM and which is a VDom element.
3) This particular branch does the following:
updateDom
) to reconcile the propsOh man, unpacking this code is really tricky... I wish like hell there was a tool that would automate these spooky compression patterns so no one would need to write code like this. 😐
Anyway, thanks for the explanation. 🙂
Oh, one thought about keyed updates: I noticed you use the user-supplied key and then fall back to a generated key, e.g.:
key = userKey || " " + elementType + nextIndexFor(elementType)
In my own experiments, the element type is always part of the key - something like:
key = elementType + " " + (userKey || nextIndexFor(elementType))
Otherwise, if we were to diff between, say, <div key="foo">
and <img key="foo">
, these would be seen as the same element, wouldn't they?
Any reason this got stranded here?
I think the only issue was the element-type missing from the key?
Other than that, it looks good to go?
This is the preview of the 0.4.0 release
Changelog
k
property that can be used for hinting the reconciliation keybrotli
instead ofgzip
to maintain the 512 byte contractual limit