Skip to content

Commit

Permalink
[Main] - Bump Changes to 0.51.0 Base Version (#105)
Browse files Browse the repository at this point in the history
* empty commit

* Bump changes to 0.50.1 Changes Version (#106)

* update to changes PR #1879

* add changes from #1882

* fix build on xcode 13.4.1

* Bump changes to 0.50.2 Changes Version (#107)

* apply changes from #1883

* apply changes from #1890

* apply changes from #1893

* apply changes from #1897

* Bump changes to 0.50.3 Changes Version (#108)

* update package.swift & missmatch version podspec

* apply partial changes from #1907

* Bump changes to 0.51.0 Changes Version (#109)

* apply partial changes from #1917

* fix test on RxTca

* apply changes from #1911

* apply changes from #1920

* apply changes from #1900
  • Loading branch information
dikasetiadi authored Jan 3, 2024
1 parent 5c9fff0 commit 0f3be75
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "0.8.1"),
.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.3.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.9.1"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.2.0")
],
targets: [
Expand Down
118 changes: 61 additions & 57 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<Action>) async -> Void)
case run(TaskPriority? = nil, @Sendable (Send) async -> Void)
}

@usableFromInline
Expand Down Expand Up @@ -76,7 +76,7 @@ extension Effect {
/// struct State { … }
/// enum FeatureAction {
/// case factButtonTapped
/// case faceResponse(TaskResult<String>)
/// case factResponse(TaskResult<String>)
/// }
/// @Dependency(\.numberFact) var numberFact
///
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<Action>) async throws -> Void,
catch handler: (@Sendable (Error, Send<Action>) async -> Void)? = nil,
operation: @escaping @Sendable (Send) async throws -> Void,
catch handler: (@Sendable (Error, Send) async -> Void)? = nil,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
Expand Down Expand Up @@ -269,62 +269,66 @@ 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<Action> {
public let send: @MainActor (Action) -> Void
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
}
public init(send: @escaping @MainActor (Action) -> Void) {
self.send = send
}

/// 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)
}
/// 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?
// /// 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)
// }
// }
// 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
9 changes: 9 additions & 0 deletions Sources/RxComposableArchitecture/Internal/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

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 @@ -238,7 +238,7 @@ public struct AnyReducer<State, Action, Environment> {
localAction,
toLocalEnvironment(globalEnvironment)
)
.map(toLocalAction.embed)
.map { toLocalAction.embed($0) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public struct _ReducerPrinter<State, Action> {
extension _ReducerPrinter {
public static var customDump: Self {
Self { receivedAction, oldState, newState in
@Dependency(\.context) var context
guard context != .preview else { return }
var target = ""
target.write("received action:\n")
CustomDump.customDump(receivedAction, to: &target, indent: 2)
Expand All @@ -49,8 +47,6 @@ extension _ReducerPrinter {

public static var actionLabels: Self {
Self { receivedAction, _, _ in
@Dependency(\.context) var context
guard context != .preview else { return }
print("received action: \(debugCaseOutput(receivedAction))")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension ReducerProtocol {
public func forEach<ElementState, ElementAction, ID: Hashable, Element: ReducerProtocol>(
_ toElementsState: WritableKeyPath<State, IdentifiedArray<ID, ElementState>>,
action toElementAction: CasePath<Action, (ID, ElementAction)>,
@ReducerBuilder<ElementState, ElementAction> _ element: () -> Element,
@ReducerBuilder<ElementState, ElementAction> element: () -> Element,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,6 @@ public struct _IfCaseLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>
}
defer { state = self.toChildState.embed(childState) }
return self.child.reduce(into: &childState, action: childAction)
.map(self.toChildAction.embed)
.map { self.toChildAction.embed($0) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ public struct _IfLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>: Re
return .none
}
return self.child.reduce(into: &state[keyPath: self.toChildState]!, action: childAction)
.map(self.toChildAction.embed)
.map { self.toChildAction.embed($0) }
}
}
10 changes: 5 additions & 5 deletions Sources/RxComposableArchitecture/Reducer/Reducers/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
public init<ChildState, ChildAction>(
state toChildState: WritableKeyPath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> _ child: () -> Child
@ReducerBuilder<ChildState, ChildAction> child: () -> Child
) where ChildState == Child.State, ChildAction == Child.Action {
self.init(
toChildState: .keyPath(toChildState),
Expand All @@ -159,7 +159,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
public init<ChildState, ChildAction>(
state toChildState: OptionalPath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> _ child: () -> Child,
@ReducerBuilder<ChildState, ChildAction> child: () -> Child,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
Expand Down Expand Up @@ -234,7 +234,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
public init<ChildState, ChildAction>(
state toChildState: CasePath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> _ child: () -> Child,
@ReducerBuilder<ChildState, ChildAction> child: () -> Child,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
Expand All @@ -256,7 +256,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
case let .keyPath(toChildState):
return self.child
.reduce(into: &state[keyPath: toChildState], action: childAction)
.map(self.toChildAction.embed)
.map { self.toChildAction.embed($0) }
case let .optionalPath(toChildState, file, fileID, line):
guard var childState = toChildState.extract(from: state) else {
runtimeWarn(
Expand Down Expand Up @@ -296,7 +296,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP

return self.child
.reduce(into: &childState, action: childAction)
.map(self.toChildAction.embed)
.map { self.toChildAction.embed($0) }
}
}
}
Loading

0 comments on commit 0f3be75

Please sign in to comment.