Skip to content

Commit

Permalink
Fix build/tests, run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
p4checo committed Jan 26, 2023
1 parent 2bf9e8b commit c3f39b7
Show file tree
Hide file tree
Showing 19 changed files with 2,557 additions and 2,555 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ``ComposableArchitecture/EffectPublisher/send(_:)``
# ``ComposableArchitecture/EffectProducer/send(_:)``

## Topics

### Animating actions

- ``EffectPublisher/send(_:animation:)``
- ``EffectProducer/send(_:animation:)``
52 changes: 27 additions & 25 deletions Sources/ComposableArchitecture/Effect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactiveSwift
import XCTestDynamicOverlay

#if canImport(SwiftUI)
import SwiftUI
import SwiftUI
#endif

/// This type is deprecated in favor of ``EffectTask``. See its documentation for more information.
Expand Down Expand Up @@ -115,7 +115,7 @@ extension EffectProducer {
/// > This is only an issue if using the Combine interface of ``EffectProducer`` as mentioned
/// > above. If you are using Swift's concurrency tools and the `.task`, `.run`, and
/// > `.fireAndForget` functions on ``EffectTask``, then threading is automatically handled for you.
public typealias EffectTask<Action> = EffectPublisher<Action, Never>
public typealias EffectTask<Action> = EffectProducer<Action, Never>

extension EffectProducer where Failure == Never {
/// Wraps an asynchronous unit of work in an effect.
Expand Down Expand Up @@ -340,20 +340,22 @@ extension EffectProducer where Failure == Never {
Self(value: action)
}

/// Initializes an effect that immediately emits the action passed in.
///
/// > Note: We do not recommend using `Effect.send` to share logic. Instead, limit usage to
/// > child-parent communication, where a child may want to emit a "delegate" action for a parent
/// > to listen to.
/// >
/// > For more information, see <doc:Performance#Sharing-logic-with-actions>.
///
/// - Parameters:
/// - action: The action that is immediately emitted by the effect.
/// - animation: An animation.
public static func send(_ action: Action, animation: Animation? = nil) -> Self {
Self(value: action).animation(animation)
}
#if canImport(SwiftUI)
/// Initializes an effect that immediately emits the action passed in.
///
/// > Note: We do not recommend using `Effect.send` to share logic. Instead, limit usage to
/// > child-parent communication, where a child may want to emit a "delegate" action for a parent
/// > to listen to.
/// >
/// > For more information, see <doc:Performance#Sharing-logic-with-actions>.
///
/// - Parameters:
/// - action: The action that is immediately emitted by the effect.
/// - animation: An animation.
public static func send(_ action: Action, animation: Animation? = nil) -> Self {
Self(value: action).animation(animation)
}
#endif
}

/// A type that can send actions back into the system when used from
Expand Down Expand Up @@ -401,15 +403,15 @@ public struct Send<Action> {
}

#if canImport(SwiftUI)
/// Sends an action back into the system from an effect with animation.
///
/// - Parameters:
/// - action: An action.
/// - animation: An animation.
public func callAsFunction(_ action: Action, animation: Animation?) {
callAsFunction(action, transaction: Transaction(animation: animation))
}
/// Sends an action back into the system from an effect with animation.
///
/// - Parameters:
/// - action: An action.
/// - animation: An animation.
public func callAsFunction(_ action: Action, animation: Animation?) {
callAsFunction(action, transaction: Transaction(animation: animation))
}

/// Sends an action back into the system from an effect with transaction.
///
/// - Parameters:
Expand Down
94 changes: 47 additions & 47 deletions Sources/ComposableArchitecture/Effects/Animation.swift
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#if canImport(SwiftUI)
import ReactiveSwift
import SwiftUI
import SwiftUI

extension EffectProducer {
/// Wraps the emission of each element with SwiftUI's `withAnimation`.
///
/// ```swift
/// case .buttonTapped:
/// return .task {
/// .activityResponse(await self.apiClient.fetchActivity())
/// }
/// .animation()
/// ```
///
/// - Parameter animation: An animation.
/// Wraps the emission of each element with SwiftUI's `withAnimation`.
///
/// ```swift
/// case .buttonTapped:
/// return .task {
/// .activityResponse(await self.apiClient.fetchActivity())
/// }
/// .animation()
/// ```
///
/// - Parameter animation: An animation.
/// - Returns: An effect.
public func animation(_ animation: Animation? = .default) -> Self {
self.transaction(Transaction(animation: animation))
}
public func animation(_ animation: Animation? = .default) -> Self {
self.transaction(Transaction(animation: animation))
}

/// Wraps the emission of each element with SwiftUI's `withTransaction`.
///
/// ```swift
/// case .buttonTapped:
/// var transaction = Transaction(animation: .default)
/// transaction.disablesAnimations = true
/// return .task {
/// .activityResponse(await self.apiClient.fetchActivity())
/// }
/// .transaction(transaction)
/// ```
///
/// - Parameter transaction: A transaction.
/// - Returns: A publisher.
public func transaction(_ transaction: Transaction) -> Self {
switch self.operation {
case .none:
return .none
/// Wraps the emission of each element with SwiftUI's `withTransaction`.
///
/// ```swift
/// case .buttonTapped:
/// var transaction = Transaction(animation: .default)
/// transaction.disablesAnimations = true
/// return .task {
/// .activityResponse(await self.apiClient.fetchActivity())
/// }
/// .transaction(transaction)
/// ```
///
/// - Parameter transaction: A transaction.
/// - Returns: A publisher.
public func transaction(_ transaction: Transaction) -> Self {
switch self.operation {
case .none:
return .none
case let .producer(producer):
return Self(
return Self(
operation: .producer(
SignalProducer<Action, Failure> { observer, _ in
producer.start { action in
Expand All @@ -56,21 +56,21 @@ import SwiftUI
}
}
}
)
)
)
case let .run(priority, operation):
return Self(
operation: .run(priority) { send in
await operation(
Send { value in
withTransaction(transaction) {
send(value)
case let .run(priority, operation):
return Self(
operation: .run(priority) { send in
await operation(
Send { value in
withTransaction(transaction) {
send(value)
}
}
}
)
}
)
)
}
)
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension EffectProducer where Action == Date, Failure == Never {
/// initialState: Feature.State(),
/// reducer: Feature()
/// ) {
/// $0.mainQueue = mainQueue
/// $0.mainQueueScheduler = mainQueue
/// }
///
/// await store.send(.startButtonTapped)
Expand Down
Loading

0 comments on commit c3f39b7

Please sign in to comment.