From f93b8dd657870c742e49b902585fa90defedfebe Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Fri, 22 Jul 2022 00:36:37 -0700 Subject: [PATCH 1/4] Add debugging property --- Sources/Nodes/Classes/AbstractFlow.swift | 29 ++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sources/Nodes/Classes/AbstractFlow.swift b/Sources/Nodes/Classes/AbstractFlow.swift index a20db366c..c46a3fd5a 100644 --- a/Sources/Nodes/Classes/AbstractFlow.swift +++ b/Sources/Nodes/Classes/AbstractFlow.swift @@ -12,6 +12,16 @@ */ public protocol FlowRetaining: AnyObject {} +#if DEBUG + +public struct Node { + + public let name: String + public let children: [Node] +} + +#endif + /** * The interface used for passing `Flow` instances into ``AbstractFlow`` instance methods which enables * attaching and detaching child `Flow` instances within the base class implementation. @@ -19,6 +29,12 @@ public protocol FlowRetaining: AnyObject {} /// @mockable public protocol Flow: AnyObject { + #if DEBUG + + var node: Node { get } + + #endif + /// A Boolean value indicating whether the `Flow` instance has started. var isStarted: Bool { get } @@ -54,6 +70,19 @@ public protocol Flow: AnyObject { */ open class AbstractFlow: Flow { + #if DEBUG + + public var node: Node { + let type: String = "\(type(of: self))" + let suffix: String = "FlowImp" + let name: String = type.hasSuffix(suffix) + ? String(type.dropLast(suffix.count)) + : type + return Node(name: name, children: flowController.flows.map(\.node)) + } + + #endif + /// A Boolean value indicating whether the `Flow` instance has started. public var isStarted: Bool { _context.isActive From 796af47abb68fac773c05d57872c4bf7f44f8f53 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Fri, 22 Jul 2022 00:59:56 -0700 Subject: [PATCH 2/4] Fix test mock --- Tests/NodesTests/NodesMocks.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tests/NodesTests/NodesMocks.swift b/Tests/NodesTests/NodesMocks.swift index 70d1872a1..997c98442 100644 --- a/Tests/NodesTests/NodesMocks.swift +++ b/Tests/NodesTests/NodesMocks.swift @@ -6,7 +6,7 @@ // Created by Christopher Fuller on 5/4/21. // -import Nodes +@testable import Nodes extension Equatable where Self: AnyObject { @@ -17,6 +17,8 @@ extension Equatable where Self: AnyObject { internal final class FlowMock: Flow, Equatable { + internal let node: Node = .init(name: "mock", children: []) + // swiftlint:disable:next redundant_type_annotation internal private(set) var isStarted: Bool = false From 45e539f4f3f65be407b535977e1c1c0f98e611a3 Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Fri, 22 Jul 2022 09:37:03 -0700 Subject: [PATCH 3/4] Rename property --- Sources/Nodes/Classes/AbstractFlow.swift | 6 +++--- Sources/Nodes/Controllers/FlowController.swift | 8 ++++++++ Tests/NodesTests/NodesMocks.swift | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Sources/Nodes/Classes/AbstractFlow.swift b/Sources/Nodes/Classes/AbstractFlow.swift index c46a3fd5a..81de679af 100644 --- a/Sources/Nodes/Classes/AbstractFlow.swift +++ b/Sources/Nodes/Classes/AbstractFlow.swift @@ -31,7 +31,7 @@ public protocol Flow: AnyObject { #if DEBUG - var node: Node { get } + var tree: Node { get } #endif @@ -72,13 +72,13 @@ open class AbstractFlow: Flow { #if DEBUG - public var node: Node { + public var tree: Node { let type: String = "\(type(of: self))" let suffix: String = "FlowImp" let name: String = type.hasSuffix(suffix) ? String(type.dropLast(suffix.count)) : type - return Node(name: name, children: flowController.flows.map(\.node)) + return Node(name: name, children: flowController.tree.children) } #endif diff --git a/Sources/Nodes/Controllers/FlowController.swift b/Sources/Nodes/Controllers/FlowController.swift index dbd3e639f..60952fc23 100644 --- a/Sources/Nodes/Controllers/FlowController.swift +++ b/Sources/Nodes/Controllers/FlowController.swift @@ -13,6 +13,14 @@ */ public final class FlowController { + #if DEBUG + + public var tree: Node { + Node.init(name: "", children: flows.map(\.tree)) + } + + #endif + /// The array of `Flow` instances managed by the ``FlowController``. public private(set) var flows: [Flow] = [] diff --git a/Tests/NodesTests/NodesMocks.swift b/Tests/NodesTests/NodesMocks.swift index 997c98442..19d12f6bd 100644 --- a/Tests/NodesTests/NodesMocks.swift +++ b/Tests/NodesTests/NodesMocks.swift @@ -17,7 +17,7 @@ extension Equatable where Self: AnyObject { internal final class FlowMock: Flow, Equatable { - internal let node: Node = .init(name: "mock", children: []) + internal let tree: Node = .init(name: "", children: []) // swiftlint:disable:next redundant_type_annotation internal private(set) var isStarted: Bool = false From e9c890294530a101712108c67c2c0bc706b17d2d Mon Sep 17 00:00:00 2001 From: Christopher Fuller Date: Fri, 22 Jul 2022 10:04:15 -0700 Subject: [PATCH 4/4] Remove init --- Sources/Nodes/Controllers/FlowController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Nodes/Controllers/FlowController.swift b/Sources/Nodes/Controllers/FlowController.swift index 60952fc23..72b4ac535 100644 --- a/Sources/Nodes/Controllers/FlowController.swift +++ b/Sources/Nodes/Controllers/FlowController.swift @@ -16,7 +16,7 @@ public final class FlowController { #if DEBUG public var tree: Node { - Node.init(name: "", children: flows.map(\.tree)) + Node(name: "", children: flows.map(\.tree)) } #endif