@@ -196,17 +196,20 @@ def _watch_bind_dict(self, name, expression):
196196 def update (self , new : set [str ], old : set [str ] | None ):
197197 if old is None :
198198 old = set ()
199- for attr in new - old :
200- self ._watch_bind (
201- attr ,
202- lambda attr = attr : expression ()[attr ],
203- )
204-
205- for attr in old - new :
206- if f"bind:{ attr } " in self ._watchers :
207- del self ._watchers [f"bind:{ attr } " ]
208- # Perform cleanup
209- self ._rem_attr (attr )
199+ if additional_attrs := new - old :
200+ for attr in additional_attrs :
201+ self ._watch_bind (
202+ attr ,
203+ lambda attr = attr : expression ()[attr ],
204+ )
205+
206+ if removed_attrs := old - new :
207+ for attr in removed_attrs :
208+ if f"bind:{ attr } " in self ._watchers :
209+ unwatch = self ._watchers .pop (f"bind:{ attr } " )
210+ unwatch ()
211+ # Perform cleanup
212+ self ._rem_attr (attr )
210213
211214 self ._watchers [f"bind_dict:{ name } " ] = watch (
212215 lambda : set (expression ().keys ()),
@@ -294,19 +297,17 @@ def unmount(self, destroy=True):
294297 self ._events = {}
295298 # Disable the fn and callback of the watcher to disable
296299 # any 'false' triggers
297- for watcher in self ._watchers .values ():
298- watcher .fn = lambda : ()
299- watcher .callback = None
300+ for unwatch in self ._watchers .values ():
301+ unwatch ()
300302 self ._watchers = {}
301303 self ._condition = None
302304 self .tag = None
303305 else :
304306 self .element = None
305307 # Disable the fn and callback of the watcher to disable
306308 # any 'false' triggers
307- for watcher in self ._watchers .values ():
308- watcher .fn = lambda : ()
309- watcher .callback = None
309+ for unwatch in self ._watchers .values ():
310+ unwatch ()
310311 self ._watchers = {}
311312
312313 # TODO: maybe control flow fragments needs another custom 'parenting'
@@ -871,8 +872,7 @@ def unmount(self, destroy=True):
871872 self ._attributes = {}
872873 self ._events = {}
873874 if self ._type_watcher :
874- self ._type_watcher .fn = lambda : ()
875- self ._type_watcher .callback = None
875+ self ._type_watcher ()
876876 self ._type_watcher = None
877877 self ._condition = None
878878 self ._expression = None
0 commit comments