Skip to content

Commit 3a8a5a1

Browse files
committed
compare definition ID to see if changed in layout
1 parent 742cf57 commit 3a8a5a1

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/idom/core/component.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(
5151
self._kwargs = kwargs
5252
self.key = key
5353

54+
@property
55+
def definition_id(self) -> int:
56+
return id(self._func)
57+
5458
def render(self) -> VdomDict:
5559
model = self._func(*self._args, **self._kwargs)
5660
if isinstance(model, ComponentType):

src/idom/core/layout.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,10 @@ def _update_component_model_state(
511511
life_cycle_state=(
512512
_update_life_cycle_state(old_model_state.life_cycle_state, new_component)
513513
if old_model_state.is_component_state
514+
and (
515+
old_model_state.life_cycle_state.component.definition_id
516+
== new_component.definition_id
517+
)
514518
else _make_life_cycle_state(new_component, schedule_render)
515519
),
516520
)

src/idom/core/proto.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class ComponentType(Protocol):
3232
key: Key | None
3333
"""An identifier which is unique amongst a component's immediate siblings"""
3434

35+
definition_id: int
36+
"""A globally unique identifier for this component definition.
37+
38+
Usually the :func:`id` of this class or an underlying function.
39+
"""
40+
3541
def render(self) -> VdomDict:
3642
"""Render the component's :class:`VdomDict`."""
3743

0 commit comments

Comments
 (0)