Skip to content

Commit 2b8ca79

Browse files
committed
Move SignalProducer APIs to a new source file.
1 parent f4621f1 commit 2b8ca79

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
5BC88F98246B191200394C63 /* Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC88F97246B191200394C63 /* Loop.swift */; };
4444
5BC88F99246B191200394C63 /* Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC88F97246B191200394C63 /* Loop.swift */; };
4545
5BC88F9A246B191200394C63 /* Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC88F97246B191200394C63 /* Loop.swift */; };
46+
5BC88F9C246B1CDE00394C63 /* SignalProducer+Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC88F9B246B1CDE00394C63 /* SignalProducer+Loop.swift */; };
47+
5BC88F9D246B1CDE00394C63 /* SignalProducer+Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC88F9B246B1CDE00394C63 /* SignalProducer+Loop.swift */; };
48+
5BC88F9E246B1CDE00394C63 /* SignalProducer+Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BC88F9B246B1CDE00394C63 /* SignalProducer+Loop.swift */; };
4649
656A9C9323D0813500EFB2F8 /* FeedbackLoop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656A9C9223D0813500EFB2F8 /* FeedbackLoop.swift */; };
4750
656A9C9423D0813500EFB2F8 /* FeedbackLoop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656A9C9223D0813500EFB2F8 /* FeedbackLoop.swift */; };
4851
656A9C9523D0813500EFB2F8 /* FeedbackLoop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 656A9C9223D0813500EFB2F8 /* FeedbackLoop.swift */; };
@@ -191,6 +194,7 @@
191194
5BC88F8D246B11DE00394C63 /* LoopBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoopBox.swift; sourceTree = "<group>"; };
192195
5BC88F91246B17B200394C63 /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
193196
5BC88F97246B191200394C63 /* Loop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loop.swift; sourceTree = "<group>"; };
197+
5BC88F9B246B1CDE00394C63 /* SignalProducer+Loop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SignalProducer+Loop.swift"; sourceTree = "<group>"; };
194198
656A9C9223D0813500EFB2F8 /* FeedbackLoop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackLoop.swift; sourceTree = "<group>"; };
195199
656A9C9623D0826100EFB2F8 /* FeedbackEventConsumer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbackEventConsumer.swift; sourceTree = "<group>"; };
196200
65761B2523CF20EF004D5506 /* Floodgate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Floodgate.swift; sourceTree = "<group>"; };
@@ -391,6 +395,7 @@
391395
isa = PBXGroup;
392396
children = (
393397
5BC88F97246B191200394C63 /* Loop.swift */,
398+
5BC88F9B246B1CDE00394C63 /* SignalProducer+Loop.swift */,
394399
656A9C9223D0813500EFB2F8 /* FeedbackLoop.swift */,
395400
5BC88F91246B17B200394C63 /* Context.swift */,
396401
585CD87A239E6A39004BE9CC /* Reducer.swift */,
@@ -713,6 +718,7 @@
713718
A9509BE4551098F4A5503820 /* Feedback.swift in Sources */,
714719
A950943401765BB90FA846B2 /* SignalProducer+System.swift in Sources */,
715720
65761B2E23CF4CA2004D5506 /* NSLock+Extensions.swift in Sources */,
721+
5BC88F9C246B1CDE00394C63 /* SignalProducer+Loop.swift in Sources */,
716722
5BC88F92246B17B200394C63 /* Context.swift in Sources */,
717723
585CD87B239E6A39004BE9CC /* Reducer.swift in Sources */,
718724
9AD5D42D1F97375E00E6AE5A /* Property+System.swift in Sources */,
@@ -750,6 +756,7 @@
750756
65F8C260218371A800924657 /* Feedback.swift in Sources */,
751757
65F8C261218371A800924657 /* SignalProducer+System.swift in Sources */,
752758
65761B2F23CF4CA2004D5506 /* NSLock+Extensions.swift in Sources */,
759+
5BC88F9D246B1CDE00394C63 /* SignalProducer+Loop.swift in Sources */,
753760
5BC88F93246B17B200394C63 /* Context.swift in Sources */,
754761
585CD87C239E6A3E004BE9CC /* Reducer.swift in Sources */,
755762
65F8C262218371A800924657 /* Property+System.swift in Sources */,
@@ -768,6 +775,7 @@
768775
65F8C26F218371AC00924657 /* Feedback.swift in Sources */,
769776
65F8C270218371AC00924657 /* SignalProducer+System.swift in Sources */,
770777
65761B3023CF4CA2004D5506 /* NSLock+Extensions.swift in Sources */,
778+
5BC88F9E246B1CDE00394C63 /* SignalProducer+Loop.swift in Sources */,
771779
5BC88F94246B17B200394C63 /* Context.swift in Sources */,
772780
585CD87D239E6A3E004BE9CC /* Reducer.swift in Sources */,
773781
65F8C271218371AC00924657 /* Property+System.swift in Sources */,

Loop/Legacy/Property+System.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ReactiveSwift
22

33
extension Property {
4-
@available(*, deprecated, message:"Please migrate to FeedbackLoop")
4+
@available(*, deprecated, message:"Please migrate to Loop")
55
public convenience init<Event>(
66
initial: Value,
77
scheduler: Scheduler = QueueScheduler.main,
@@ -19,7 +19,7 @@ extension Property {
1919
self.init(capturing: state)
2020
}
2121

22-
@available(*, deprecated, message:"Please migrate to FeedbackLoop")
22+
@available(*, deprecated, message:"Please migrate to Loop")
2323
public convenience init<Event>(
2424
initial: Value,
2525
scheduler: Scheduler = QueueScheduler.main,

Loop/Legacy/SignalProducer+System.swift

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,54 +69,7 @@ extension SignalProducer where Error == Never {
6969
return system(initial: initial, reduce: reduce, feedbacks: feedbacks)
7070
}
7171

72-
private static func deferred(_ producer: @escaping (Lifetime) -> SignalProducer<Value, Error>) -> SignalProducer<Value, Error> {
72+
internal static func deferred(_ producer: @escaping (Lifetime) -> SignalProducer<Value, Error>) -> SignalProducer<Value, Error> {
7373
return SignalProducer { $1 += producer($1).start($0) }
7474
}
7575
}
76-
77-
extension SignalProducer where Error == Never {
78-
79-
/// Feedback-controlled State Machine. The system state is represented as a `State` parameter.
80-
/// Events are represented by an `Event` parameter. It represents all the possible Events that may occur in the System
81-
/// Feedback defines an effect that may change the State.
82-
83-
/// - parameters:
84-
/// - initial: An initial `State` of the system.
85-
/// - scheduler: A Scheduler used for Events synchronisation
86-
/// - reduce: A function that produces a new State of a system by applying an Event
87-
/// - feedbacks: A Feedback loops that produces Events depending on the system's `State`
88-
/// - returns: A SignalProducer that emits current the state of the System
89-
public static func feedbackLoop<Event>(
90-
initial: Value,
91-
reduce: @escaping (inout Value, Event) -> Void,
92-
feedbacks: [Loop<Value, Event>.Feedback]
93-
) -> SignalProducer<Value, Never> {
94-
return SignalProducer.deferred { downstreamLifetime in
95-
let feedbackLoop = RootLoopBox(
96-
initial: initial,
97-
reducer: reduce,
98-
feedbacks: feedbacks,
99-
startImmediately: false
100-
)
101-
downstreamLifetime.observeEnded(feedbackLoop.stop)
102-
return feedbackLoop.producer.on(started: feedbackLoop.start)
103-
}
104-
}
105-
106-
/// Feedback-controlled State Machine. The system state is represented as a `State` parameter.
107-
/// Events are represented by `Event` parameter. It represents all possible Events that may occur in the System
108-
/// Feedback defines an effect that may change the State.
109-
110-
/// - parameters:
111-
/// - initial: An initial `State` of the system.
112-
/// - reduce: A that produces a new State of the system by applying an Event
113-
/// - feedbacks: A Feedback loops that produces Events depending on the system's state.
114-
/// - returns: A SignalProducer that emits current the state of the System
115-
public static func feedbackLoop<Event>(
116-
initial: Value,
117-
reduce: @escaping (inout Value, Event) -> Void,
118-
feedbacks: Loop<Value, Event>.Feedback...
119-
) -> SignalProducer<Value, Error> {
120-
return feedbackLoop(initial: initial, reduce: reduce, feedbacks: feedbacks)
121-
}
122-
}

Loop/Public/SignalProducer+Loop.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import ReactiveSwift
2+
3+
extension SignalProducer where Error == Never {
4+
5+
/// Feedback-controlled State Machine. The system state is represented as a `State` parameter.
6+
/// Events are represented by an `Event` parameter. It represents all the possible Events that may occur in the System
7+
/// Feedback defines an effect that may change the State.
8+
9+
/// - parameters:
10+
/// - initial: An initial `State` of the system.
11+
/// - scheduler: A Scheduler used for Events synchronisation
12+
/// - reduce: A function that produces a new State of a system by applying an Event
13+
/// - feedbacks: A Feedback loops that produces Events depending on the system's `State`
14+
/// - returns: A SignalProducer that emits current the state of the System
15+
public static func feedbackLoop<Event>(
16+
initial: Value,
17+
reduce: @escaping (inout Value, Event) -> Void,
18+
feedbacks: [Loop<Value, Event>.Feedback]
19+
) -> SignalProducer<Value, Never> {
20+
return SignalProducer.deferred { downstreamLifetime in
21+
let feedbackLoop = RootLoopBox(
22+
initial: initial,
23+
reducer: reduce,
24+
feedbacks: feedbacks,
25+
startImmediately: false
26+
)
27+
downstreamLifetime.observeEnded(feedbackLoop.stop)
28+
return feedbackLoop.producer.on(started: feedbackLoop.start)
29+
}
30+
}
31+
32+
/// Feedback-controlled State Machine. The system state is represented as a `State` parameter.
33+
/// Events are represented by `Event` parameter. It represents all possible Events that may occur in the System
34+
/// Feedback defines an effect that may change the State.
35+
36+
/// - parameters:
37+
/// - initial: An initial `State` of the system.
38+
/// - reduce: A that produces a new State of the system by applying an Event
39+
/// - feedbacks: A Feedback loops that produces Events depending on the system's state.
40+
/// - returns: A SignalProducer that emits current the state of the System
41+
public static func feedbackLoop<Event>(
42+
initial: Value,
43+
reduce: @escaping (inout Value, Event) -> Void,
44+
feedbacks: Loop<Value, Event>.Feedback...
45+
) -> SignalProducer<Value, Error> {
46+
return feedbackLoop(initial: initial, reduce: reduce, feedbacks: feedbacks)
47+
}
48+
}

0 commit comments

Comments
 (0)