Closed jridgewell closed 6 years ago
It would be nice to be able to also gracefully handle helper functions. For example, you could have:
function render() {
elementOpen('div');
if (...) { helperOne(); }
if (...) { helperTwo(); }
elementClose('div');
elementOpen('div');
if (...) { helperTwo(); }
if (...) { helperOne(); }
elementClose('div');
}
So you wouldn't necessarily be able to have a monotonic increasing typeId
for both helper functions. This could be solved by setting or passing some sort of "base" typeId
, which the helper could add to, but would make generating the code a bit more difficult.
I think the idea good as-is though, just might want to have some mechanism or guidance on how to handle helper functions.
Hmm, good thought.
How about assuming, but not enforcing, monotonic? We warn (in dev mode) when it's violated, and reset the "expected" to the lower value?
Closing since we no longer have typeId
and keys no longer need to be unique. We could revisit this for keys, but I think it wouldbe better to handle always reusing, regardless of if the keys are increasing or not.
I love the
typeId
idea, but we still have a problem in one direction:What if we enforce that the
typeId
is a monotonic increasing int? That way we have 3 scenarios:currentNode
'stypeId
typeId
nextSibling
directionnextSibling
directionThe current
typeId
handles scenario 1 perfectly, and bumbles 2 (it treats anytypeId
mismatch as a "insert this element before the current"). But it utterly fails 3. But with monotonic increasing, we have the information to decide what to do:typeId
is lessAdditionally, these should not be some runtime int that increases with every call to
open
. It has to be statically assigned for us to reap the rewards (though the runtime increasing int will just get us back to the current behavior).Note that the
typeId
int can be repeated, so this is totally fine:So, in dev mode:
typeId
s occurring in this parent element must be>
"expected"