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

should __componentCache be global?

maparent opened this issue · comments

In this line, we see that recursive component creation passes the ancestor down in the parent variable.

vdom.children = vdom.children.map(child => createComponent(child, parent, _idx));

(vs vdom.children = vdom.children.map(child => createComponent(child, vdom, _idx));)
This means that, in this line:
let component = parent.__componentCache[key];

we're using the ancestor's cache if rendering the ancestor, and the parent's cache if rendering the parent. I have observed cache miss and recreation of components for that reason. (sometimes with missing sub-components, but that last part could be a problem on my side.)
I tried using vdom and ran into other issues with missing elements. I'm also not sure about the intent here.
The issue with a global cache might be ID collision; a local cache would fail on a drag and drop, but that's a lesser concern.
Either way, I think it would be good to make sure it is used consistently.