Skip to content

Commit 2058549

Browse files
mbrandonwmluisbrown
authored andcommitted
Add animation operator to Effect. (#1134)
* Add animation operator to Effect. * Define it only on Effect.
1 parent 67a510d commit 2058549

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#if canImport(SwiftUI)
2+
import ReactiveSwift
3+
import SwiftUI
4+
5+
extension Effect {
6+
/// Wraps the emission of each element with SwiftUI's `withAnimation`.
7+
///
8+
/// This publisher is most useful when using with ``Effect/task(priority:operation:)-2czg0``
9+
///
10+
/// ```swift
11+
/// case .buttonTapped:
12+
/// return .task {
13+
/// .activityResponse(await environment.apiClient.fetchActivity())
14+
/// }
15+
/// .animation()
16+
/// ```
17+
///
18+
/// - Parameter animation: An animation.
19+
/// - Returns: A publisher.
20+
public func animation(_ animation: Animation? = .default) -> Self {
21+
SignalProducer { observer, _ in
22+
self.start { action in
23+
switch action {
24+
case let .value(value):
25+
withAnimation(animation) {
26+
observer.send(value: value)
27+
}
28+
case .completed:
29+
observer.sendCompleted()
30+
case let .failed(error):
31+
observer.send(error: error)
32+
case .interrupted:
33+
observer.sendInterrupted()
34+
}
35+
}
36+
}
37+
}
38+
}
39+
#endif

Sources/ComposableArchitecture/TestSupport/TestStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@
175175

176176
/// The current state.
177177
///
178-
/// When read from a trailing closure assertion in ``send`` or ``receive``, it will equal the
179-
/// `inout` state passed to the closure.
178+
/// When read from a trailing closure assertion in ``send(_:_:file:line:)`` or
179+
/// ``receive(_:_:file:line:)``, it will equal the `inout` state passed to the closure.
180180
public private(set) var state: State
181181

182182
private let file: StaticString

0 commit comments

Comments
 (0)