From e55e79480fa08ae183e280898d5fd344f7d4fcb0 Mon Sep 17 00:00:00 2001 From: pjechris Date: Thu, 4 Jul 2024 11:26:59 +0200 Subject: [PATCH] [entity] fix use storeAlias to nullify (#69) --- Sources/CohesionKit/EntityStore.swift | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/Sources/CohesionKit/EntityStore.swift b/Sources/CohesionKit/EntityStore.swift index 4342961..f6398c0 100644 --- a/Sources/CohesionKit/EntityStore.swift +++ b/Sources/CohesionKit/EntityStore.swift @@ -200,7 +200,7 @@ public class EntityStore { return node } - private func storeAlias(content: T, key: AliasKey, modifiedAt: Stamp?) { + private func storeAlias(content: T?, key: AliasKey, modifiedAt: Stamp?) { let aliasNode = refAliases[safe: key, onChange: registry.enqueueChange(for:)] let aliasContainer = AliasContainer(key: key, content: content) @@ -350,14 +350,9 @@ extension EntityStore { /// Removes an alias from the storage public func removeAlias(named: AliasKey) { transaction { - if let alias = refAliases[named] { - do { - try alias.updateEntity(AliasContainer(key: named, content: nil), modifiedAt: nil) - logger?.didUnregisterAlias(named) - } - catch { - - } + if refAliases[named] != nil { + storeAlias(content: nil, key: named, modifiedAt: nil) + logger?.didUnregisterAlias(named) } } } @@ -365,14 +360,9 @@ extension EntityStore { /// Removes an alias from the storage public func removeAlias(named: AliasKey) { transaction { - if let alias = refAliases[named] { - do { - try alias.updateEntity(AliasContainer(key: named, content: nil), modifiedAt: nil) - logger?.didUnregisterAlias(named) - } - catch { - - } + if refAliases[named] != nil { + storeAlias(content: nil, key: named, modifiedAt: nil) + logger?.didUnregisterAlias(named) } }