Add Node.existingOrNewChildNode — recycles an existing node. Creates a new node only when needed.

This commit is contained in:
Brent Simmons 2017-12-16 11:15:36 -08:00
parent b19d15ed3f
commit 0221eda956
1 changed files with 8 additions and 0 deletions

View File

@ -81,6 +81,14 @@ public final class Node: Hashable {
return node
}
public func existingOrNewChildNode(with representedObject: AnyObject) -> Node {
if let node = childNodeRepresentingObject(representedObject) {
return node
}
return createChildNode(representedObject)
}
public func createChildNode(_ representedObject: AnyObject) -> Node {
// Just creates doesnt add it.