From 21668ef49291003b77ade4b2acc7ec9021351ce7 Mon Sep 17 00:00:00 2001 From: pjechris Date: Sun, 4 Aug 2024 20:35:22 +0200 Subject: [PATCH] use ObjectKey --- Sources/CohesionKit/Observer/ObserverRegistry.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/CohesionKit/Observer/ObserverRegistry.swift b/Sources/CohesionKit/Observer/ObserverRegistry.swift index 8453bdc..4bae0e6 100644 --- a/Sources/CohesionKit/Observer/ObserverRegistry.swift +++ b/Sources/CohesionKit/Observer/ObserverRegistry.swift @@ -9,6 +9,10 @@ extension ObjectKey { self.init(key.hashValue) } + + init(_ node: EntityNode) { + self.init(of: T.self, id: node.hashValue) + } } /// Registers observers associated to an ``EntityNode``. @@ -41,7 +45,7 @@ class ObserverRegistry { } } - return subscribeHandler(handler, for: node, key: node.hashValue) + return subscribeHandler(handler, for: node, key: ObjectKey(node)) } /// Add an observer handler to multiple nodes. @@ -63,7 +67,7 @@ class ObserverRegistry { } } - let subscriptions = nodes.map { node in subscribeHandler(handler, for: node, key: node.hashValue) } + let subscriptions = nodes.map { node in subscribeHandler(handler, for: node, key: ObjectKey(node)) } return Subscription { subscriptions.forEach { $0.unsubscribe() } @@ -72,7 +76,7 @@ class ObserverRegistry { /// Mark a node as changed. Observers won't be notified of the change until ``postChanges`` is called func enqueueChange(for node: EntityNode) { - enqueueChange(for: node, key: node.hashValue) + enqueueChange(for: node, key: ObjectKey(node)) } func enqueueChange(for node: EntityNode, key: ObjectKey) { @@ -80,7 +84,7 @@ class ObserverRegistry { } func hasPendingChange(for node: EntityNode) -> Bool { - hasPendingChange(for: node.hashValue) + hasPendingChange(for: ObjectKey(node)) } func hasPendingChange(for key: ObjectKey) -> Bool {