Skip to content

Commit a17a57e

Browse files
committed
add element and component identity
At the moment, whenever a particular branch of a layout is updated, all the state (i.e. hooks and event handlers) that live within that branch are thrown away and reconstructed. Given IDOM’s current implementation for Layout this is unavoidable. To resolve this issue, we need to add a concept of “keys” which can be used to indicate the identity of an element within the layout structure. For example, if you have a list of elements that get re-ordered when a button is pressed, their state should be preserved, and reassigned to their new location in the layout. By default React requires keys to be used to communicate element identity whenever the order or number of simbling elements can change. While there are clear performance benefits for adhering to this stipulation, it’s often confusing for new developers. React has the further advantage of the JSX syntax, which makes it easier for the program to determine exactly when keys must be supplied by the user. To make the experience for new users simpler, and due to a lack of inforcement via JSX, IDOM will be to assume that any element without a key is new. Thus, for IDOM, keys will primarilly be a tool for optimization rather than a functional requirement.
1 parent 897a30c commit a17a57e

File tree

5 files changed

+261
-217
lines changed

5 files changed

+261
-217
lines changed

src/idom/core/hooks.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
from logging import getLogger
35
from threading import get_ident as get_thread_id
@@ -20,6 +22,7 @@
2022

2123
from typing_extensions import Protocol
2224

25+
import idom
2326
from idom.utils import Ref
2427

2528
from .component import AbstractComponent
@@ -384,10 +387,10 @@ class LifeCycleHook:
384387
def __init__(
385388
self,
386389
component: AbstractComponent,
387-
schedule_render: Callable[[AbstractComponent], None],
390+
layout: idom.core.layout.Layout,
388391
) -> None:
389392
self.component = component
390-
self._schedule_render_callback = schedule_render
393+
self._schedule_render_callback = layout.update
391394
self._schedule_render_later = False
392395
self._is_rendering = False
393396
self._rendered_atleast_once = False

0 commit comments

Comments
 (0)