Skip to content

Commit d04faf9

Browse files
committed
Rename validate_serialized_vdom to validate_vdom
also add comment about why we inject extra validation in debug mode
1 parent f7a59f2 commit d04faf9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/idom/core/layout.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from .events import EventHandler, EventTarget
2525
from .hooks import LifeCycleHook
2626
from .utils import CannotAccessResource, HasAsyncResources, async_resource
27-
from .vdom import validate_serialized_vdom
27+
from .vdom import validate_vdom
2828

2929

3030
logger = getLogger(__name__)
@@ -104,13 +104,17 @@ async def render(self) -> LayoutUpdate:
104104
return self._create_layout_update(component)
105105

106106
if IDOM_DEBUG_MODE.get():
107+
# If in debug mode inject a function that ensures all returned updates
108+
# contain valid VDOM models. We only do this in debug mode in order to
109+
# avoid unnecessarily impacting performance.
110+
107111
_debug_render = render
108112

109113
@wraps(_debug_render)
110114
async def render(self) -> LayoutUpdate:
111115
# Ensure that the model is valid VDOM on each render
112116
result = await self._debug_render()
113-
validate_serialized_vdom(self._component_states[id(self.root)].model)
117+
validate_vdom(self._component_states[id(self.root)].model)
114118
return result
115119

116120
@async_resource

src/idom/core/vdom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
}
6464

6565

66-
validate_serialized_vdom = compile_json_schema(VDOM_JSON_SCHEMA)
66+
validate_vdom = compile_json_schema(VDOM_JSON_SCHEMA)
6767

6868

6969
class ImportSourceDict(TypedDict):

tests/test_core/test_vdom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from fastjsonschema import JsonSchemaException
33

44
import idom
5-
from idom.core.vdom import component, make_vdom_constructor, validate_serialized_vdom
5+
from idom.core.vdom import component, make_vdom_constructor, validate_vdom
66

77

88
fake_events = idom.Events()
@@ -213,7 +213,7 @@ def MyComponentWithChildrenAndAttributes(children, x):
213213
],
214214
)
215215
def test_valid_vdom(value):
216-
validate_serialized_vdom(value)
216+
validate_vdom(value)
217217

218218

219219
@pytest.mark.parametrize(
@@ -312,4 +312,4 @@ def test_valid_vdom(value):
312312
)
313313
def test_invalid_vdom(value, error_message_pattern):
314314
with pytest.raises(JsonSchemaException, match=error_message_pattern):
315-
validate_serialized_vdom(value)
315+
validate_vdom(value)

0 commit comments

Comments
 (0)