@@ -173,7 +173,7 @@ def test_list_logged_excptions():
173173 assert logged_errors == [the_error ]
174174
175175
176- async def test_hostwap_update_on_change (display : DisplayFixture ):
176+ async def test_hotswap_update_on_change (display : DisplayFixture ):
177177 """Ensure shared hotswapping works
178178
179179 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):
183183 hotswap component to be updated
184184 """
185185
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 )
188188
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 )
192191
193- return constructor
192+ def hotswap_3 ():
193+ return html .div ({"id" : "hotswap-3" }, 3 )
194194
195195 @component
196196 def ButtonSwapsDivs ():
197197 count = Ref (0 )
198+ mount , hostswap = _hotswap (update_on_change = True )
198199
199200 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+ )
209213
210214 await display .show (ButtonSwapsDivs )
211215
212216 client_incr_button = await display .page .wait_for_selector ("#incr-button" )
213217
218+ await client_incr_button .click ()
214219 await display .page .wait_for_selector ("#hotswap-1" )
215220 await client_incr_button .click ()
216221 await display .page .wait_for_selector ("#hotswap-2" )
0 commit comments