yysun / apprun

AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

Home Page:https://apprun.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

updateProps may include children

maparent opened this issue · comments

I have been doing some (admittedly complex) experiments which end up with a component receiving updateProps with its complete current state, which normally includes children. Of course, trying to assign children on the htmlElement fails here. Do you think children should be special-cased, or should I find a way to eliminate or filter children from the state?

P.S. I have tried eliminating children from the state with no adverse effect so far, and that solves my issue, but I am not sure it's the best course of action.

Here is the example of handling children using the mounted function.
https://github.com/yysun/apprun/blob/V2/demo-html/components/counter.tsx

Thank you for this, it shows well how to use the children passed; but that was not my issue. I now understand where it comes from; it was arising in the example I gave of a recursive tree. (I updated that code to fix the bug better.)

Let me recap: When a component is rendered, the props acquire children here. My code would propagate that state in the parent's state, which would then re-propagate it to the child with children in the props. The child would get re-rendered, and break at the assignment of children to the HTML element here, as mentioned. So it is an artefact of my strategy for state sharing; I am closing the issue. I still think it would be good to special case children in the update function, in case someone introduces that name in the props by mistake, but now that I understand where it came from, I doubt it's likely in normal usage.
Thank you.