Skip to content

Commit

Permalink
[node] reintroduce applyChildrenChanges property (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjechris committed Jan 4, 2024
1 parent f0f1d50 commit d0f9354
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/CohesionKit/EntityStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 183,11 @@ public class EntityStore {
// clear all children to avoid a removed child to be kept as child
node.removeAllChildren()

node.applyChildrenChanges = false
for keyPathContainer in entity.nestedEntitiesKeyPaths {
keyPathContainer.accept(node, entity, modifiedAt, storeVisitor)
}
node.applyChildrenChanges = true

do {
try node.updateEntity(entity, modifiedAt: modifiedAt)
Expand Down
5 changes: 5 additions & 0 deletions Sources/CohesionKit/Storage/EntityNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 19,7 @@ class EntityNode<T>: AnyEntityNode {

var value: Any { ref.value }

var applyChildrenChanges = true
/// An observable entity reference
let ref: Observable<T>

Expand Down Expand Up @@ -84,6 85,10 @@ class EntityNode<T>: AnyEntityNode {
}

let subscription = childNode.ref.addObserver { [unowned self] newValue in
guard self.applyChildrenChanges else {
return
}

update(&self.ref.value, newValue)
self.onChange?(self)
}
Expand Down

0 comments on commit d0f9354

Please sign in to comment.