@@ -173,7 +173,7 @@ def test_list_logged_excptions():
173
173
assert logged_errors == [the_error ]
174
174
175
175
176
- async def test_hostwap_update_on_change (display : DisplayFixture ):
176
+ async def test_hotswap_update_on_change (display : DisplayFixture ):
177
177
"""Ensure shared hotswapping works
178
178
179
179
This basically means that previously rendered views of a hotswap component get updated
@@ -183,34 +183,39 @@ async def test_hostwap_update_on_change(display: DisplayFixture):
183
183
hotswap component to be updated
184
184
"""
185
185
186
- def make_next_count_constructor ( count ):
187
- """We need to construct a new function so they're different when we set_state"""
186
+ def hotswap_1 ( ):
187
+ return html . div ({ "id" : "hotswap-1" }, 1 )
188
188
189
- def constructor ():
190
- count .current += 1
191
- return html .div ({"id" : f"hotswap-{ count .current } " }, count .current )
189
+ def hotswap_2 ():
190
+ return html .div ({"id" : "hotswap-2" }, 2 )
192
191
193
- return constructor
192
+ def hotswap_3 ():
193
+ return html .div ({"id" : "hotswap-3" }, 3 )
194
194
195
195
@component
196
196
def ButtonSwapsDivs ():
197
197
count = Ref (0 )
198
+ mount , hostswap = _hotswap (update_on_change = True )
198
199
199
200
async def on_click (event ):
200
- mount (make_next_count_constructor (count ))
201
-
202
- incr = html .button ({"on_click" : on_click , "id" : "incr-button" }, "incr" )
203
-
204
- mount , make_hostswap = _hotswap (update_on_change = True )
205
- mount (make_next_count_constructor (count ))
206
- hotswap_view = make_hostswap ()
207
-
208
- return html .div (incr , hotswap_view )
201
+ count .set_current (count .current + 1 )
202
+ if count .current == 1 :
203
+ mount (hotswap_1 )
204
+ if count .current == 2 :
205
+ mount (hotswap_2 )
206
+ if count .current == 3 :
207
+ mount (hotswap_3 )
208
+
209
+ return html .div (
210
+ html .button ({"on_click" : on_click , "id" : "incr-button" }, "incr" ),
211
+ hostswap (),
212
+ )
209
213
210
214
await display .show (ButtonSwapsDivs )
211
215
212
216
client_incr_button = await display .page .wait_for_selector ("#incr-button" )
213
217
218
+ await client_incr_button .click ()
214
219
await display .page .wait_for_selector ("#hotswap-1" )
215
220
await client_incr_button .click ()
216
221
await display .page .wait_for_selector ("#hotswap-2" )
0 commit comments