1
1
import Foundation
2
2
import ReactiveSwift
3
3
4
- /// The `Effect` type encapsulates a unit of work that can be run in the outside world, and can feed
5
- /// data back to the `Store`. It is the perfect place to do side effects, such as network requests,
4
+ /// The `` Effect` ` type encapsulates a unit of work that can be run in the outside world, and can feed
5
+ /// data back to the `` Store` `. It is the perfect place to do side effects, such as network requests,
6
6
/// saving/loading from disk, creating timers, interacting with dependencies, and more.
7
7
///
8
- /// Effects are returned from reducers so that the `Store` can perform the effects after the reducer
9
- /// is done running. It is important to note that `Store` is not thread safe, and so all effects
8
+ /// Effects are returned from reducers so that the `` Store` ` can perform the effects after the reducer
9
+ /// is done running. It is important to note that `` Store` ` is not thread safe, and so all effects
10
10
/// must receive values on the same thread, **and** if the store is being used to drive UI then it
11
11
/// must receive values on the main thread.
12
12
///
@@ -59,8 +59,8 @@ extension Effect {
59
59
}
60
60
}
61
61
62
- /// An Effect that waits until it is started before running
63
- /// the supplied closure to create a new Effect, whose values
62
+ /// An `` Effect`` that waits until it is started before running
63
+ /// the supplied closure to create a new `` Effect`` , whose values
64
64
/// are then sent to the subscriber of this effect.
65
65
public static func deferred( _ createProducer: @escaping ( ) -> SignalProducer < Value , Error > )
66
66
-> SignalProducer < Value , Error >
@@ -72,25 +72,29 @@ extension Effect {
72
72
/// Creates an effect that can supply a single value asynchronously in the future.
73
73
///
74
74
/// This can be helpful for converting APIs that are callback-based into ones that deal with
75
- /// `Effect`s.
75
+ /// `` Effect` `s.
76
76
///
77
77
/// For example, to create an effect that delivers an integer after waiting a second:
78
78
///
79
- /// Effect<Int, Never>.future { callback in
80
- /// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
81
- /// callback(.success(42))
82
- /// }
83
- /// }
79
+ /// ```swift
80
+ /// Effect<Int, Never>.future { callback in
81
+ /// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
82
+ /// callback(.success(42))
83
+ /// }
84
+ /// }
85
+ /// ```
84
86
///
85
87
/// Note that you can only deliver a single value to the `callback`. If you send more they will be
86
88
/// discarded:
87
89
///
88
- /// Effect<Int, Never>.future { callback in
89
- /// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
90
- /// callback(.success(42))
91
- /// callback(.success(1729)) // Will not be emitted by the effect
92
- /// }
93
- /// }
90
+ /// ```swift
91
+ /// Effect<Int, Never>.future { callback in
92
+ /// DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
93
+ /// callback(.success(42))
94
+ /// callback(.success(1729)) // Will not be emitted by the effect
95
+ /// }
96
+ /// }
97
+ /// ```
94
98
///
95
99
/// - Parameter attemptToFulfill: A closure that takes a `callback` as an argument which can be
96
100
/// used to feed it `Result<Output, Failure>` values.
@@ -110,32 +114,36 @@ extension Effect {
110
114
}
111
115
}
112
116
113
- /// Turns any producer into an `Effect` that cannot fail by wrapping its output and failure in a
114
- /// result.
117
+ /// Turns any publisher into an `` Effect`` that cannot fail by wrapping its output and failure in
118
+ /// a result.
115
119
///
116
120
/// This can be useful when you are working with a failing API but want to deliver its data to an
117
121
/// action that handles both success and failure.
118
122
///
119
- /// case .buttonTapped:
120
- /// return fetchUser(id: 1)
121
- /// .catchToEffect()
122
- /// .map(ProfileAction.userResponse)
123
+ /// ```swift
124
+ /// case .buttonTapped:
125
+ /// return fetchUser(id: 1)
126
+ /// .catchToEffect()
127
+ /// .map(ProfileAction.userResponse)
128
+ /// ```
123
129
///
124
130
/// - Returns: An effect that wraps `self`.
125
131
public func catchToEffect( ) -> Effect < Result < Value , Error > , Never > {
126
132
self . map ( Result< Value, Error> . success)
127
133
. flatMapError { Effect < Result < Value , Error > , Never > ( value: Result . failure ( $0) ) }
128
134
}
129
135
130
- /// Turns any publisher into an `Effect` for any output and failure type by ignoring all output
136
+ /// Turns any `SignalProducer` into an `` Effect` ` for any output and failure type by ignoring all output
131
137
/// and any failure.
132
138
///
133
139
/// This is useful for times you want to fire off an effect but don't want to feed any data back
134
140
/// into the system. It can automatically promote an effect to your reducer's domain.
135
141
///
136
- /// case .buttonTapped:
137
- /// return analyticsClient.track("Button Tapped")
138
- /// .fireAndForget()
142
+ /// ```swift
143
+ /// case .buttonTapped:
144
+ /// return analyticsClient.track("Button Tapped")
145
+ /// .fireAndForget()
146
+ /// ```
139
147
///
140
148
/// - Parameters:
141
149
/// - outputType: An output type.
@@ -154,7 +162,7 @@ extension Effect {
154
162
155
163
extension Effect where Self. Error == Never {
156
164
157
- /// Assigns each element from an Effect to a property on an object.
165
+ /// Assigns each element from an `` Effect`` to a property on an object.
158
166
///
159
167
/// - Parameters:
160
168
/// - keyPath: The key path of the property to assign.
0 commit comments