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

The componentCache is never cleared. Surprising behaviour on recreated components.

maparent opened this issue · comments

There is a global componentCache declared in component.ts. I do not see any code to delete elements from this cache, so it would leak memory in a major way. I think some last-created, or last-accessed queue with a maximum size would be helpful.

I discovered it because of another issue: I was deleting and creating components, and found that re-created elements with the same ID as a previously deleted one would have the state of the old element. This was unexpected. I think we also need a way to declare that a component is dead.

The componentCache is for the dev-tool to see all components. I can make it on/off based on the app['debug'] flag.

Can you please show an example of deleting and re-creating components?

Disabling the cache unless debug would make sense to me, no idea about performance impact?
As for reappearing components: I have put an example in this gist. Try creating a branch with sub-elements, deleting it, recreating the deleted element, and you'll get the sub-elements back.

On cache performance: You seem to imply here that it is useful to avoid redrawing children when the parent is refreshed, which is a case I do care about. Another case I would care about is when a child is reparented (eg in a drag and drop operation.)

Pushed the fix to use app['debug'] for componentCache: ffa560a.