Skip to content

Commit

Permalink
[entity] fix use storeAlias to nullify (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjechris authored Jul 4, 2024
1 parent 055a2d2 commit e55e794
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions Sources/CohesionKit/EntityStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public class EntityStore {
return node
}

private func storeAlias<T>(content: T, key: AliasKey<T>, modifiedAt: Stamp?) {
private func storeAlias<T>(content: T?, key: AliasKey<T>, modifiedAt: Stamp?) {
let aliasNode = refAliases[safe: key, onChange: registry.enqueueChange(for:)]
let aliasContainer = AliasContainer(key: key, content: content)

Expand Down Expand Up @@ -350,29 +350,19 @@ extension EntityStore {
/// Removes an alias from the storage
public func removeAlias<T>(named: AliasKey<T>) {
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)
}
}
}

/// Removes an alias from the storage
public func removeAlias<C: Collection>(named: AliasKey<C>) {
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)
}
}

Expand Down

0 comments on commit e55e794

Please sign in to comment.