File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed
Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -65,11 +65,18 @@ private extension AnyReactor {
6565 navigationPath. cleanup ( )
6666 }
6767
68- // public func popTo<R: Reactor>(_ reactor: R.Type) {
69- // let lastReactorIndex = navigationPath.count - 1
70- // let poppingToReactorAtIndex = navigationPath.keys.lastIndex(where: { $0 is R }) ?? lastReactorIndex
71- // navigationPath.removeLast(lastReactorIndex - poppingToReactorAtIndex)
72- // }
68+ public func popTo< R: Reactor > ( _ reactor: R . Type ) {
69+ var currentNode = navigationPath. lastActiveNode
70+ while var parent = currentNode. parent, !parent. value. isTabs {
71+ let parentReactor = parent. value. reactor
72+ if parentReactor? . is ( ofType: reactor) ?? false {
73+ parent. value. mutator ? ( nil )
74+ return
75+ } else {
76+ currentNode = parent
77+ }
78+ }
79+ }
7380
7481}
7582
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import Collections
99
1010public typealias Tree < T> = TreeNode < T >
1111
12+ // MARK: - Class
13+
1214public class TreeNode < T> {
1315 public var value : T
1416
@@ -29,6 +31,8 @@ public class TreeNode<T> {
2931 }
3032}
3133
34+ // MARK: - Depth
35+
3236extension TreeNode {
3337
3438 var depth : Int {
@@ -43,6 +47,8 @@ extension TreeNode {
4347
4448}
4549
50+ // MARK: - String description
51+
4652extension TreeNode : CustomStringConvertible {
4753
4854 public var description : String {
@@ -55,6 +61,8 @@ extension TreeNode: CustomStringConvertible {
5561
5662}
5763
64+ // MARK: - Search
65+
5866extension TreeNode {
5967
6068 public func depthFirstSearch( _ value: T , predicate: ( T , T ) -> Bool ) -> TreeNode ? {
You can’t perform that action at this time.
0 commit comments