Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump changes to 0.52.0 Changes Version #111

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"repositoryURL": "https://github.com/pointfreeco/swift-case-paths",
"state": {
"branch": null,
"revision": "ce9c0d897db8a840c39de64caaa9b60119cf4be8",
"version": "0.8.1"
"revision": "fc45e7b2cfece9dd80b5a45e6469ffe67fe67984",
"version": "0.14.1"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/ReactiveX/RxSwift", from: "5.1.1"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.8.1"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.14.0"),
.package(name: "Benchmark", url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.8.5"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.9.1"),
Expand Down
120 changes: 59 additions & 61 deletions Sources/RxComposableArchitecture/Effect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct Effect<Action> {
enum Operation {
case none
case observable(Observable<Action>)
case run(TaskPriority? = nil, @Sendable (Send) async -> Void)
case run(TaskPriority? = nil, @Sendable (Send<Action>) async -> Void)
}

@usableFromInline
Expand Down Expand Up @@ -198,8 +198,8 @@ extension Effect {
/// - Returns: An effect wrapping the given asynchronous work.
public static func run(
priority: TaskPriority? = nil,
operation: @escaping @Sendable (Send) async throws -> Void,
catch handler: (@Sendable (Error, Send) async -> Void)? = nil,
operation: @escaping @Sendable (Send<Action>) async throws -> Void,
catch handler: (@Sendable (Error, Send<Action>) async -> Void)? = nil,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
Expand Down Expand Up @@ -269,66 +269,64 @@ extension Effect {
}
}

extension Effect {
/// A type that can send actions back into the system when used from
/// ``Effect/run(priority:operation:catch:file:fileID:line:)``.
///
/// This type implements [`callAsFunction`][callAsFunction] so that you invoke it as a function
/// rather than calling methods on it:
///
/// ```swift
/// return .run { send in
/// send(.started)
/// defer { send(.finished) }
/// for await event in self.events {
/// send(.event(event))
/// }
/// }
/// ```
///
/// You can also send actions with animation:
///
/// ```swift
/// send(.started, animation: .spring())
/// defer { send(.finished, animation: .default) }
/// ```
///
/// See ``Effect/run(priority:operation:catch:file:fileID:line:)`` for more information on how to
/// use this value to construct effects that can emit any number of times in an asynchronous
/// context.
///
/// [callAsFunction]: https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID622
@MainActor
public struct Send {
public let send: @MainActor (Action) -> Void

public init(send: @escaping @MainActor (Action) -> Void) {
self.send = send
}
/// A type that can send actions back into the system when used from
/// ``Effect/run(priority:operation:catch:file:fileID:line:)``.
///
/// This type implements [`callAsFunction`][callAsFunction] so that you invoke it as a function
/// rather than calling methods on it:
///
/// ```swift
/// return .run { send in
/// send(.started)
/// defer { send(.finished) }
/// for await event in self.events {
/// send(.event(event))
/// }
/// }
/// ```
///
/// You can also send actions with animation:
///
/// ```swift
/// send(.started, animation: .spring())
/// defer { send(.finished, animation: .default) }
/// ```
///
/// See ``Effect/run(priority:operation:catch:file:fileID:line:)`` for more information on how to
/// use this value to construct effects that can emit any number of times in an asynchronous
/// context.
///
/// [callAsFunction]: https://docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID622
@MainActor
public struct Send<Action> {
public let send: @MainActor (Action) -> Void

/// Sends an action back into the system from an effect.
///
/// - Parameter action: An action.
public func callAsFunction(_ action: Action) {
guard !Task.isCancelled else { return }
self.send(action)
}
public init(send: @escaping @MainActor (Action) -> Void) {
self.send = send
}

// TODO: Daniel: Should we enable this in our fork?
// a little notes: since this func is related to SwiftUI, we can revisit later on
//
// /// 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?) {
// guard !Task.isCancelled else { return }
// withAnimation(animation) {
// self(action)
// }
// }
/// Sends an action back into the system from an effect.
///
/// - Parameter action: An action.
public func callAsFunction(_ action: Action) {
guard !Task.isCancelled else { return }
self.send(action)
}

// TODO: Daniel: Should we enable this in our fork?
// a little notes: since this func is related to SwiftUI, we can revisit later on
//
// /// 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?) {
// guard !Task.isCancelled else { return }
// withAnimation(animation) {
// self(action)
// }
// }
}

// MARK: - Composing Effects
Expand Down Expand Up @@ -472,7 +470,7 @@ extension Effect {
return .init(
operation: .run(priority) { send in
await operation(
Send { action in
Send<Action> { action in
send(transform(action))
}
)
Expand Down
9 changes: 0 additions & 9 deletions Sources/RxComposableArchitecture/Internal/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@

import Darwin

// MARK: - Deprecated after 0.50.4

@available(
*,
deprecated,
message: "Use 'Effect<Action>.Send' instead."
)
public typealias Send<Action> = Effect<Action>.Send

// MARK: - Deprecated after 0.42.0:

/// This API has been soft-deprecated in favor of ``ReducerProtocol``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ extension Store {
reducer: Reduce(reducer, environment: environment),
useNewScope: useNewScope
)

/// We mark this flag as false, since this init is for old style reducer
///
self.isReducerProtocolStore = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension ReducerProtocol {
/// - Parameter printer: A printer for printing debug messages.
/// - Returns: A reducer that prints debug messages for all received actions.
@inlinable
@warn_unqualified_access
public func _printChanges(
_ printer: _ReducerPrinter<State, Action>? = .customDump
) -> _PrintChangesReducer<Self> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extension ReducerProtocol {
/// - value: The new value to set for the item specified by `keyPath`.
/// - Returns: A reducer that has the given value set in its dependencies.
@inlinable
@warn_unqualified_access
public func dependency<Value>(
_ keyPath: WritableKeyPath<DependencyValues, Value>,
_ value: Value
Expand Down Expand Up @@ -119,6 +120,7 @@ extension ReducerProtocol {
/// - transform: A closure that is handed a mutable instance of the value specified by the key
/// path.
@inlinable
@warn_unqualified_access
public func transformDependency<V>(
_ keyPath: WritableKeyPath<DependencyValues, V>,
transform: @escaping (inout V) -> Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extension ReducerProtocol {
/// state.
/// - Returns: A reducer that combines the child reducer with the parent reducer.
@inlinable
@warn_unqualified_access
public func forEach<ElementState, ElementAction, ID: Hashable, Element: ReducerProtocol>(
_ toElementsState: WritableKeyPath<State, IdentifiedArray<ID, ElementState>>,
action toElementAction: CasePath<Action, (ID, ElementAction)>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extension ReducerProtocol {
/// present
/// - Returns: A reducer that combines the child reducer with the parent reducer.
@inlinable
@warn_unqualified_access
public func ifCaseLet<CaseState, CaseAction, Case: ReducerProtocol>(
_ toCaseState: CasePath<State, CaseState>,
action toCaseAction: CasePath<Action, CaseAction>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension ReducerProtocol {
/// state.
/// - Returns: A reducer that combines the child reducer with the parent reducer.
@inlinable
@warn_unqualified_access
public func ifLet<WrappedState, WrappedAction, Wrapped: ReducerProtocol>(
_ toWrappedState: WritableKeyPath<State, WrappedState?>,
action toWrappedAction: CasePath<Action, WrappedAction>,
Expand Down
20 changes: 13 additions & 7 deletions Sources/RxComposableArchitecture/Reducer/Reducers/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/// ```
///
/// A parent reducer with a domain that holds onto the child domain can use
/// ``init(state:action:_:)`` to embed the child reducer in its
/// ``init(state:action:child:)`` to embed the child reducer in its
/// ``ReducerProtocol/body-swift.property-7foai``:
///
/// ```swift
Expand Down Expand Up @@ -58,7 +58,7 @@
/// ## Enum state
///
/// The ``Scope`` reducer also works when state is modeled as an enum, not just a struct. In that
/// case you can use ``init(state:action:_:file:fileID:line:)`` to specify a case path that
/// case you can use ``init(state:action:child:file:fileID:line:)`` to specify a case path that
/// identifies the case of state you want to scope to.
///
/// For example, if your state was modeled as an enum for unloaded/loading/loaded, you could
Expand Down Expand Up @@ -96,7 +96,8 @@
/// For an alternative to using ``Scope`` with state case paths that enforces the order, check out
/// the ``ifCaseLet(_:action:then:file:fileID:line:)`` operator.
public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerProtocol {
public enum StatePath {
@usableFromInline
enum StatePath {
case keyPath(WritableKeyPath<ParentState, Child.State>)
case optionalPath(
OptionalPath<ParentState, Child.State>,
Expand All @@ -105,10 +106,15 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
line: UInt
)
}

public let toChildState: StatePath
public let toChildAction: CasePath<ParentAction, Child.Action>
public let child: Child

@usableFromInline
let toChildState: StatePath

@usableFromInline
let toChildAction: CasePath<ParentAction, Child.Action>

@usableFromInline
let child: Child

@usableFromInline
init(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extension ReducerProtocol {
/// - log: An `OSLog` to use for signposts.
/// - Returns: A reducer that has been enhanced with instrumentation.
@inlinable
@warn_unqualified_access
public func signpost(
_ prefix: String = "",
log: OSLog = OSLog(
Expand Down
Loading