@@ -66,11 +66,11 @@ ever be removed from the model. Then you'll just need to call and await a
66
66
async with idom.Layout(ClickCount()) as layout:
67
67
patch = await layout.render()
68
68
69
- The layout also handles the triggering of event handlers. Normally this is done
70
- automatically by a :ref: `Dispatcher <Layout Dispatcher >`, but for now we'll do it manually.
71
- We can use a trick to hard-code the `` event_handler_id `` so we can pass it, and a fake
72
- event , to the layout's :meth: `~idom.core.layout.Layout.dispatch ` method. Then we just
73
- have to re-render the layout and see what changed:
69
+ The layout also handles the triggering of event handlers. Normally these are
70
+ automatically sent to a :ref: `Dispatcher <Layout Dispatcher >`, but for now we'll do it
71
+ manually. To do this we need to pass a fake event with its "target" (event handler
72
+ identifier) , to the layout's :meth: `~idom.core.layout.Layout.dispatch ` method, after
73
+ which we can re-render and see what changed:
74
74
75
75
.. testcode ::
76
76
@@ -85,10 +85,10 @@ have to re-render the layout and see what changed:
85
85
[f"Click count: {count}"],
86
86
)
87
87
88
- async with idom.Layout(ClickCount(key="something ")) as layout:
88
+ async with idom.Layout(ClickCount(key="test-component ")) as layout:
89
89
patch_1 = await layout.render()
90
90
91
- fake_event = LayoutEvent("/something /onClick", [{}])
91
+ fake_event = LayoutEvent(target="/test-component /onClick", data= [{}])
92
92
await layout.dispatch(fake_event)
93
93
patch_2 = await layout.render()
94
94
@@ -98,6 +98,12 @@ have to re-render the layout and see what changed:
98
98
99
99
assert count_did_increment
100
100
101
+ .. note ::
102
+
103
+ Don't worry about the format of the layout event's ``target ``. Its an internal
104
+ detail of the layout's implementation that is neither neccessary to understanding
105
+ how things work, nor is it part of the interface clients should rely on.
106
+
101
107
102
108
Layout Dispatcher
103
109
-----------------
@@ -129,7 +135,7 @@ callback that's called by the dispatcher to events it should execute.
129
135
130
136
131
137
async def recv():
132
- event = LayoutEvent("/my -component/onClick", [{}])
138
+ event = LayoutEvent(target="/test -component/onClick", data= [{}])
133
139
134
140
# We need this so we don't flood the render loop with events.
135
141
# In practice this is never an issue since events won't arrive
@@ -140,7 +146,7 @@ callback that's called by the dispatcher to events it should execute.
140
146
141
147
142
148
async with SingleViewDispatcher(
143
- idom.Layout(ClickCount(key="my -component"))
149
+ idom.Layout(ClickCount(key="test -component"))
144
150
) as dispatcher:
145
151
context = None # see note below
146
152
await dispatcher.run(send, recv, context)
0 commit comments