-
-
Notifications
You must be signed in to change notification settings - Fork 926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: mysterious vnode.children nesting #2106
Comments
Ultimately it's because a bare function isn't a valid child node, you're running into some normalization code that does its best with bad input. ¯\_(ಠ_ಠ)_/¯ Stepping through it does this. A function isn't a valid attribute, so it's a child node. All children get normalized, so it goes through this function: Lines 11 to 16 in 23ebe2f
Which calls this function: Lines 6 to 10 in 23ebe2f
Which specifically is hitting this conditional: Line 8 in 23ebe2f
Which then runs this: Lines 3 to 5 in 23ebe2f
With the So ultimately the shape of what your flems returns looks like this: {
"tag": {
"view": v => v.children[0].children()
},
"attrs": {},
"children": [
{
"children": () => 'Hello!'
}
]
} and tada to execute your function you need to use |
Brilliant, thanks @tivac. I assume the generous fall-through to text node condition is there to enable things along the lines of streams' @pygy I know you've been working around the space of more formal normalisation procedures in the land of vtree disambiguation, is this particular mechanism under scrutiny? |
Isiah (not pinging him here since he's on a Mithril hiatus) suggested supporting a function as the only child for components in #2050, and I shot it down ignoring the broader context, suggesting to use an |
I can't believe I missed that issue! Now I understand the underlying logic I don't think the |
Still. that's not very clean, and it works by accident. That's undocumented, untested behaviour that may break without notice... Let's resurrect #2050. |
I'm playing around with feasibility / ergonomics studies for functor components. Precedent React convention tends towards components that expose a custom attribute / props interface and accept the view / render function in the place of
children
, which makes a certain amount of sense and certainly involves less typing ceremony.When I try to implement this pattern in Mithril I end up unexpectedly having to query
vnode.children[0].children
from the consuming component to access the function I passed in as the last argument — I would expect this to be exposed asvnode.children[0]
.Why might this be? Does this make sense to people more familiar with the internal vnode engine? Have I hit upon a dangerous ambiguity, or is this a harmless piece of implementation trivia?
Here's a minimal repro.
The text was updated successfully, but these errors were encountered: