From 57a04e5c185ca0fefe222c786d63a7585a8e8eba Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Thu, 27 Apr 2023 16:47:20 +0200 Subject: [PATCH] reworked event handler management (#47) # Conflicts: # src/Aardvark.UI/Updater.fs --- src/Aardvark.UI/Updater.fs | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Aardvark.UI/Updater.fs b/src/Aardvark.UI/Updater.fs index db1b6890..6221e577 100644 --- a/src/Aardvark.UI/Updater.fs +++ b/src/Aardvark.UI/Updater.fs @@ -260,7 +260,7 @@ module Updaters = type AttributeUpdater<'msg>(attributes : AttributeMap<'msg>) = let mutable reader = attributes.GetReader() - let registeredHandlers = Dictionary() + let registeredHandlers = System.Collections.Generic.HashSet() member x.TryGetAttrbute(name : string) = HashMap.tryFind name reader.State @@ -277,34 +277,25 @@ module Updaters = str | AttributeValue.Event evt -> let key = (id, name) - match registeredHandlers.TryGetValue key with - | (true, d) -> d.Dispose() - | _ -> () state.handlers.[key] <- evt.serverSide - let handlerDispose = { new IDisposable with member x.Dispose() = state.handlers.Remove(key) |> ignore } - registeredHandlers.[key] <- handlerDispose // add or overwrite + registeredHandlers.Add(key) |> ignore Event.toString id name evt yield JSExpr.SetAttribute(self, name, value) | Remove -> let key = (id, name) - match registeredHandlers.TryGetValue key with - | (true, d) -> - d.Dispose() - registeredHandlers.Remove(key) |> ignore - | _ -> () + registeredHandlers.Remove(key) |> ignore + state.handlers.Remove(key) |> ignore yield JSExpr.RemoveAttribute(self, name) ] - member x.Dispose() = - for kv in registeredHandlers do - kv.Value.Dispose() + member x.Destroy(state : UpdateState<'msg>) = + for k in registeredHandlers do + state.handlers.Remove(k) |> ignore registeredHandlers.Clear() reader <- Unchecked.defaultof<_> - interface IDisposable with - member x.Dispose() = x.Dispose() type EmptyUpdater<'msg>(e : EmptyNode<'msg>) = inherit AbstractUpdater<'msg>(e) @@ -328,7 +319,7 @@ module Updaters = att.Update(token, state, id, self) override x.PerformDestroy(state : UpdateState<'msg>, self : JSExpr) = - att.Dispose() + att.Destroy(state) JSExpr.Nop and InnerUpdater<'msg>(e : InnerNode<'msg>, request : Request) = @@ -461,7 +452,7 @@ module Updaters = |> JSExpr.Sequential elemReader <- Unchecked.defaultof<_> - att.Dispose() + att.Destroy(state) inner and SceneUpdater<'msg>(e : SceneNode<'msg>) as this = @@ -491,7 +482,7 @@ module Updaters = override x.PerformDestroy(state : UpdateState<'msg>, self : JSExpr) = state.scenes.Remove(x.Id.Value) |> ignore - att.Dispose() + att.Destroy(state) initial <- true JSExpr.Nop @@ -511,7 +502,7 @@ module Updaters = ] override x.PerformDestroy(state : UpdateState<'msg>, self : JSExpr) = - att.Dispose() + att.Destroy(state) JSExpr.Nop and MapUpdater<'inner, 'outer>(m : MapNode<'inner, 'outer>, inner : IUpdater<'inner>) =