Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(alias): Fix a crash when storing data after removing alias #69

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading