@@ -26,6 +26,17 @@ internal class ScopedLoopBox<RootState, RootEvent, ScopedState, ScopedEvent>: Lo
26
26
override func send( _ event: ScopedEvent ) {
27
27
root. send ( eventTransform ( event) )
28
28
}
29
+
30
+ override func scoped< S, E> (
31
+ to scope: KeyPath < ScopedState , S > ,
32
+ event: @escaping ( E ) -> ScopedEvent
33
+ ) -> LoopBoxBase < S , E > {
34
+ return ScopedLoopBox < RootState , RootEvent , S , E > (
35
+ root: self . root,
36
+ value: value. appending ( path: scope) ,
37
+ event: { [ eventTransform] in eventTransform ( event ( $0) ) }
38
+ )
39
+ }
29
40
}
30
41
31
42
internal class RootLoopBox < State, Event> : LoopBoxBase < State , Event > {
@@ -38,7 +49,7 @@ internal class RootLoopBox<State, Event>: LoopBoxBase<State, Event> {
38
49
private let token : Lifetime . Token
39
50
private let input = Loop < State , Event > . Feedback. input
40
51
41
- public override var producer : SignalProducer < State , Never > {
52
+ override var producer : SignalProducer < State , Never > {
42
53
SignalProducer { observer, lifetime in
43
54
self . floodgate. withValue { initial, hasStarted -> Void in
44
55
if hasStarted {
@@ -53,7 +64,7 @@ internal class RootLoopBox<State, Event>: LoopBoxBase<State, Event> {
53
64
}
54
65
}
55
66
56
- public init (
67
+ init (
57
68
initial: State ,
58
69
reducer: @escaping ( inout State , Event ) -> Void ,
59
70
feedbacks: [ Loop < State , Event > . Feedback ] ,
@@ -75,6 +86,13 @@ internal class RootLoopBox<State, Event>: LoopBoxBase<State, Event> {
75
86
}
76
87
}
77
88
89
+ override func scoped< S, E> (
90
+ to scope: KeyPath < State , S > ,
91
+ event: @escaping ( E ) -> Event
92
+ ) -> LoopBoxBase < S , E > {
93
+ ScopedLoopBox ( root: self , value: scope, event: event)
94
+ }
95
+
78
96
func start( ) {
79
97
floodgate. bootstrap ( )
80
98
}
@@ -97,6 +115,13 @@ internal class LoopBoxBase<State, Event> {
97
115
var producer : SignalProducer < State , Never > { subclassMustImplement ( ) }
98
116
99
117
func send( _ event: Event ) { subclassMustImplement ( ) }
118
+
119
+ func scoped< S, E> (
120
+ to scope: KeyPath < State , S > ,
121
+ event: @escaping ( E ) -> Event
122
+ ) -> LoopBoxBase < S , E > {
123
+ subclassMustImplement ( )
124
+ }
100
125
}
101
126
102
127
@inline ( never)
0 commit comments