Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 0 additions & 41 deletions BGSwift.podspec

This file was deleted.

37 changes: 21 additions & 16 deletions BGSwift/Classes/BGExtent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open class BGExtent: Hashable, CustomDebugStringConvertible {

var _added: BGMoment
public var added: BGResource { _added }
var _mirror: Mirror?

public enum Status {
case inactive
Expand All @@ -32,22 +33,6 @@ open class BGExtent: Hashable, CustomDebugStringConvertible {

self.addComponents(from: builder)

var _mirror: Mirror? = Mirror(reflecting: self)
while let mirror = _mirror, mirror.subjectType is BGExtent.Type {
mirror.children.forEach { child in
if let resource = child.value as? (any BGResourceInternal) {
if resource.debugName == nil {
resource.debugName = "\(String(describing: Self.self)).\(child.label ?? "Anonymous_Resource")"
}
} else if let behavior = child.value as? BGBehavior {
if behavior.debugName == nil {
behavior.debugName = "\(String(describing: Self.self)).\(child.label ?? "Anonymous_Behavior")"
}
}
}
_mirror = mirror.superclassMirror
}

#if DEBUG
onExtentCreated?(self)
#endif
Expand Down Expand Up @@ -121,6 +106,26 @@ open class BGExtent: Hashable, CustomDebugStringConvertible {
graph.removeExtent(resources: resources, behaviors: behaviors)
}

internal func loadDebugNames() {
if (_mirror == nil) {
_mirror = Mirror(reflecting: self)
while let mirror = _mirror, mirror.subjectType is BGExtent.Type {
mirror.children.forEach { child in
if let resource = child.value as? (any BGResourceInternal) {
if resource.debugName == nil {
resource.debugName = "\(String(describing: Self.self)).\(child.label ?? "Anonymous_Resource")"
}
} else if let behavior = child.value as? BGBehavior {
if behavior.debugName == nil {
behavior.debugName = "\(String(describing: Self.self)).\(child.label ?? "Anonymous_Behavior")"
}
}
}
_mirror = mirror.superclassMirror
}
}
}

public func sideEffect(file: String = #fileID, line: Int = #line, function: String = #function, _ body: @escaping () -> Void) {
let impulse = BGGraph.impulseString(file: file, line: line, function: function)
sideEffect(impulse, body)
Expand Down
39 changes: 36 additions & 3 deletions BGSwift/Classes/BGResource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,18 @@ public class BGMoment: BGResource, BGResourceInternal {

// MARK: BGResource

public var debugName: String?
var _debugName: String?
public var debugName: String? {
get {
if _debugName != nil {
return _debugName
} else {
self.owner?.loadDebugNames()
return _debugName
}
}
set { _debugName = newValue }
}
public var _event: BGEvent = .unknownPast

// MARK: BGResourceInternal
Expand Down Expand Up @@ -290,7 +301,18 @@ public class BGTypedMoment<Type>: BGResource, BGResourceInternal {

// MARK: BGResource

public var debugName: String?
var _debugName: String?
public var debugName: String? {
get {
if _debugName != nil {
return _debugName
} else {
self.owner?.loadDebugNames()
return _debugName
}
}
set { _debugName = newValue }
}
public var _event: BGEvent = .unknownPast

// MARK: BGResourceInternal
Expand Down Expand Up @@ -408,7 +430,18 @@ public class BGState<Type>: BGResource, BGResourceInternal {

// MARK: BGResource

public var debugName: String?
var _debugName: String?
public var debugName: String? {
get {
if _debugName != nil {
return _debugName
} else {
self.owner?.loadDebugNames()
return _debugName
}
}
set { _debugName = newValue }
}
public var _event: BGEvent = .unknownPast

// MARK: BGResourceInternal
Expand Down
Loading