@@ -70,16 +70,28 @@ def __init__(self, conn: Connection, session_id):
7070 self .__on_resize = EventHandler ()
7171 self ._add_event_handler ("resize" , self .__on_resize .handler )
7272
73- self .__on_route_change = EventHandler (lambda e : e .data )
73+ self .__last_route = None
74+
75+ def convert_route_change_event (e ):
76+ if self .__last_route == e .data :
77+ return None # avoid duplicate calls
78+ self .__last_route = e .data
79+ return RouteChangeEvent (route = e .data )
80+
81+ self .__on_route_change = EventHandler (convert_route_change_event )
7482 self ._add_event_handler ("route_change" , self .__on_route_change .handler )
75- self .__on_view_pop = EventHandler (lambda e : self .get_control (e .data ))
83+
84+ def convert_view_pop_event (e ):
85+ return ViewPopEvent (view = self .get_control (e .data ))
86+
87+ self .__on_view_pop = EventHandler (convert_view_pop_event )
7688 self ._add_event_handler ("view_pop" , self .__on_view_pop .handler )
7789
78- def convert_keyboard_event_data (e ):
90+ def convert_keyboard_event (e ):
7991 d = json .loads (e .data )
8092 return KeyboardEvent (** d )
8193
82- self .__on_keyboard_event = EventHandler (convert_keyboard_event_data )
94+ self .__on_keyboard_event = EventHandler (convert_keyboard_event )
8395 self ._add_event_handler ("keyboard_event" , self .__on_keyboard_event .handler )
8496
8597 self .__on_window_event = EventHandler ()
@@ -267,7 +279,15 @@ def show_signin(self, auth_providers="*", auth_groups=False, allow_dismiss=False
267279
268280 def go (self , route ):
269281 self .route = route
270- self .__on_route_change .handler (Event ("page" , "route_change" , self .route ))
282+ self .__on_route_change .handler (
283+ ControlEvent (
284+ target = "page" ,
285+ name = "route_change" ,
286+ data = self .route ,
287+ page = self ,
288+ control = self ,
289+ )
290+ )
271291 self .update ()
272292
273293 def signout (self ):
@@ -952,6 +972,16 @@ def dialog(self, value: Optional[Control]):
952972 self .__dialog = value
953973
954974
975+ @dataclass
976+ class RouteChangeEvent (ControlEvent ):
977+ route : str
978+
979+
980+ @dataclass
981+ class ViewPopEvent (ControlEvent ):
982+ view : View
983+
984+
955985@dataclass
956986class KeyboardEvent (ControlEvent ):
957987 key : str
0 commit comments