Skip to content

Commit fd87f4d

Browse files
committed
Add Effect DocC changes.
1 parent 933e5bf commit fd87f4d

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

Sources/ComposableArchitecture/Effect.swift

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Foundation
22
import ReactiveSwift
33

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,
66
/// saving/loading from disk, creating timers, interacting with dependencies, and more.
77
///
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
1010
/// must receive values on the same thread, **and** if the store is being used to drive UI then it
1111
/// must receive values on the main thread.
1212
///
@@ -59,8 +59,8 @@ extension Effect {
5959
}
6060
}
6161

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
6464
/// are then sent to the subscriber of this effect.
6565
public static func deferred(_ createProducer: @escaping () -> SignalProducer<Value, Error>)
6666
-> SignalProducer<Value, Error>
@@ -72,25 +72,29 @@ extension Effect {
7272
/// Creates an effect that can supply a single value asynchronously in the future.
7373
///
7474
/// This can be helpful for converting APIs that are callback-based into ones that deal with
75-
/// `Effect`s.
75+
/// ``Effect``s.
7676
///
7777
/// For example, to create an effect that delivers an integer after waiting a second:
7878
///
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+
/// ```
8486
///
8587
/// Note that you can only deliver a single value to the `callback`. If you send more they will be
8688
/// discarded:
8789
///
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+
/// ```
9498
///
9599
/// - Parameter attemptToFulfill: A closure that takes a `callback` as an argument which can be
96100
/// used to feed it `Result<Output, Failure>` values.
@@ -110,32 +114,36 @@ extension Effect {
110114
}
111115
}
112116

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.
115119
///
116120
/// This can be useful when you are working with a failing API but want to deliver its data to an
117121
/// action that handles both success and failure.
118122
///
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+
/// ```
123129
///
124130
/// - Returns: An effect that wraps `self`.
125131
public func catchToEffect() -> Effect<Result<Value, Error>, Never> {
126132
self.map(Result<Value, Error>.success)
127133
.flatMapError { Effect<Result<Value, Error>, Never>(value: Result.failure($0)) }
128134
}
129135

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
131137
/// and any failure.
132138
///
133139
/// This is useful for times you want to fire off an effect but don't want to feed any data back
134140
/// into the system. It can automatically promote an effect to your reducer's domain.
135141
///
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+
/// ```
139147
///
140148
/// - Parameters:
141149
/// - outputType: An output type.
@@ -154,7 +162,7 @@ extension Effect {
154162

155163
extension Effect where Self.Error == Never {
156164

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.
158166
///
159167
/// - Parameters:
160168
/// - keyPath: The key path of the property to assign.

0 commit comments

Comments
 (0)