File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed
Sources/ComposableArchitecture Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 175
175
176
176
/// The current state.
177
177
///
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.
180
180
public private( set) var state : State
181
181
182
182
private let file : StaticString
You can’t perform that action at this time.
0 commit comments