Containers child rendering process
Easieast (current model) would be to remove all components and then rerender all.
- Problems:
- Reference to removed child components remain in Clients id-to-widget map
- Some (expensive) detaching and attaching happens
- Focused child component loses its focus
ADVANCED MODEL
More advanced algorithm to render contained components:
loop components in container
take next component C from container
if C not exists in uidl
detach from container
add to a list that deferred process loops to removed unused I-widgets from clients it-to-widget map
// (deferred due component may be moved to an other place)
else if next PID from uidl equals PID in C
update C from UIDL
else new component will be rendered before next in old order
if component in old order is already attached
detach from current parent
update from UIDL
add to container before C
render remaining components in uidl to the end of container
This model will hopefully help to solve all above problems, but is of cource much more complicated to implement. We still may have some minor issues to keep focus on focused element during update. This would happen if widget is moved to another container or widget order has changed. Browsers don't remember focus when reattached to another position in DOM. I'd consider this a very minor problem.
Advanced algorithm would pave way for some performance tuning. If we use this kind of model, server could optimize the data sent to client quite a bit. Currently in 4.0 if one adds a label to an ordered layout or changes the order of existing components, all previously rendered components will also be sent and re-rendered. Now it could only send the new order of existing child components (unmodified) and all data from new components.
ALTERNATIVE SOLUTION
Another solution for "carbage collection" is to lauch loop that removed unattached i-widgets from id-to-widget map after each uidl handeling. Or let components request one at their will (no need to run carbage collection after label or other non-container update). This might be a bit more robust system and could be combined with advanced container rendering algorithm.
If we don't want to implement advanced rendering algorithm in containers, we need to build some logic to Client and focused widgets. All focusable widgets must notify Client when it receives focus and focus needs to be restored every time when container of focused widget was redrawn.
