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
29 changes: 29 additions & 0 deletions Sources/Nodes/Classes/AbstractFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@
*/
public protocol FlowRetaining: AnyObject {}

#if DEBUG

public struct Node {

public let name: String
public let children: [Node]
}
Comment on lines +17 to +21
Copy link
Contributor

@tinder-garricnahapetian tinder-garricnahapetian Aug 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a public init? I'm seeing failures in https://github.com/TinderApp/tinder_ios/pull/34580 related to FlowMock: Flow in various tests with error: protocol requires property 'tree' with type 'Node'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is an unfortunate oversight. I will make a PR 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we include this in this release?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or can be in the next one if it is not a blocker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#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.
*/
/// @mockable
public protocol Flow: AnyObject {

#if DEBUG

var tree: Node { get }

#endif

/// A Boolean value indicating whether the `Flow` instance has started.
var isStarted: Bool { get }

Expand Down Expand Up @@ -54,6 +70,19 @@ public protocol Flow: AnyObject {
*/
open class AbstractFlow<ContextInterfaceType, ViewControllerType>: Flow {

#if DEBUG

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.tree.children)
}

#endif

/// A Boolean value indicating whether the `Flow` instance has started.
public var isStarted: Bool {
_context.isActive
Expand Down
8 changes: 8 additions & 0 deletions Sources/Nodes/Controllers/FlowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
*/
public final class FlowController {

#if DEBUG

public var tree: Node {
Node(name: "", children: flows.map(\.tree))
}

#endif

/// The array of `Flow` instances managed by the ``FlowController``.
public private(set) var flows: [Flow] = []

Expand Down
4 changes: 3 additions & 1 deletion Tests/NodesTests/NodesMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Created by Christopher Fuller on 5/4/21.
//

import Nodes
@testable import Nodes

extension Equatable where Self: AnyObject {

Expand All @@ -17,6 +17,8 @@ extension Equatable where Self: AnyObject {

internal final class FlowMock: Flow, Equatable {

internal let tree: Node = .init(name: "", children: [])

// swiftlint:disable:next redundant_type_annotation
internal private(set) var isStarted: Bool = false

Expand Down