Skip to content

Commit

Permalink
Update Code base to 0.50.0 Version (#85)
Browse files Browse the repository at this point in the history
* 0.48.0 - fix small typos

* 0.48.0 - update docs TestStore

* 0.48.0 update again docs

* fix some test on core rxTCA

* 0.50.0 - update changes based from #1816

* fix some assert warning & add some new test cases

* add Equatable for TestStore.init based PR #1857

* add some comment related changes #1856

* Apply fix changes for ReducerBuilder from #1863

* push update package.resolved

* Remove commented code and fix warnings

* update workflow

* Revert "update workflow"

This reverts commit c795fc3.

---------

Co-authored-by: Jefferson Setiawan <jefferson.setiawan@tokopedia.com>
  • Loading branch information
dikasetiadi and jeffersonsetiawan authored Apr 3, 2023
1 parent 79d9df8 commit db994cc
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"version": "0.8.1"
}
},
{
"package": "swift-custom-dump",
"repositoryURL": "https://github.com/pointfreeco/swift-custom-dump",
"state": {
"branch": null,
"revision": "de8ba65649e7ee317b9daf27dd5eebf34bd4be57",
"version": "0.9.1"
}
},
{
"package": "xctest-dynamic-overlay",
"repositoryURL": "https://github.com/pointfreeco/xctest-dynamic-overlay",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

@_transparent
@usableFromInline
@inline(__always)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Reduce {
}

extension AnyReducer {
public init<R: ReducerProtocol>(@ReducerBuilderOf<R> _ build: @escaping (Environment) -> R)
public init<R: ReducerProtocol>(@ReducerBuilder<State, Action> _ build: @escaping (Environment) -> R)
where R.State == State, R.Action == Action {
self.init { state, action, environment in
build(environment).reduce(into: &state, action: action)
Expand Down
137 changes: 26 additions & 111 deletions Sources/RxComposableArchitecture/Reducer/ReducerBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,20 @@
/// See ``CombineReducers`` for an entry point into a reducer builder context.
@resultBuilder
public enum ReducerBuilder<State, Action> {
#if swift(>=5.7)
@inlinable
public static func buildArray(
_ reducers: [some ReducerProtocol<State, Action>]
) -> some ReducerProtocol<State, Action> {
public static func buildArray<R: ReducerProtocol>(_ reducers: [R]) -> _SequenceMany<R>
where R.State == State, R.Action == Action {
_SequenceMany(reducers: reducers)
}

@inlinable
public static func buildBlock() -> some ReducerProtocol<State, Action> {
public static func buildBlock() -> EmptyReducer<State, Action> {
EmptyReducer()
}

@inlinable
public static func buildBlock(
_ reducer: some ReducerProtocol<State, Action>
) -> some ReducerProtocol<State, Action> {
public static func buildBlock<R: ReducerProtocol>(_ reducer: R) -> R
where R.State == State, R.Action == Action {
reducer
}

Expand All @@ -44,64 +41,48 @@ public enum ReducerBuilder<State, Action> {
}

@inlinable
public static func buildExpression(
_ expression: some ReducerProtocol<State, Action>
) -> some ReducerProtocol<State, Action> {
public static func buildExpression<R: ReducerProtocol>(_ expression: R) -> R
where R.State == State, R.Action == Action {
expression
}

@inlinable
public static func buildFinalResult(
_ reducer: some ReducerProtocol<State, Action>
) -> some ReducerProtocol<State, Action> {
public static func buildFinalResult<R: ReducerProtocol>(_ reducer: R) -> R
where R.State == State, R.Action == Action {
reducer
}

@inlinable
public static func buildLimitedAvailability(
_ wrapped: some ReducerProtocol<State, Action>
) -> some ReducerProtocol<State, Action> {
_Optional(wrapped: wrapped)
public static func buildLimitedAvailability<R: ReducerProtocol>(
_ wrapped: R
) -> Reduce<State, Action>
where R.State == State, R.Action == Action {
Reduce(wrapped)
}

@inlinable
public static func buildOptional(
_ wrapped: (some ReducerProtocol<State, Action>)?
) -> some ReducerProtocol<State, Action> {
_Optional(wrapped: wrapped)
public static func buildOptional<R: ReducerProtocol>(_ wrapped: R?) -> R?
where R.State == State, R.Action == Action {
wrapped
}

@inlinable
public static func buildPartialBlock(
first: some ReducerProtocol<State, Action>
) -> some ReducerProtocol<State, Action> {
public static func buildPartialBlock<R: ReducerProtocol>(
first: R
) -> R
where R.State == State, R.Action == Action {
first
}

@inlinable
public static func buildPartialBlock(
accumulated: some ReducerProtocol<State, Action>, next: some ReducerProtocol<State, Action>
) -> some ReducerProtocol<State, Action> {
public static func buildPartialBlock<R0: ReducerProtocol, R1: ReducerProtocol>(
accumulated: R0, next: R1
) -> _Sequence<R0, R1>
where R0.State == State, R0.Action == Action, R1.State == State, R1.Action == Action {
_Sequence(accumulated, next)
}
#else
@inlinable
public static func buildArray<R: ReducerProtocol>(_ reducers: [R]) -> _SequenceMany<R>
where R.State == State, R.Action == Action {
_SequenceMany(reducers: reducers)
}

@inlinable
public static func buildBlock() -> EmptyReducer<State, Action> {
EmptyReducer()
}

@inlinable
public static func buildBlock<R: ReducerProtocol>(_ reducer: R) -> R
where R.State == State, R.Action == Action {
reducer
}

#if swift(<5.7)
@inlinable
public static func buildBlock<
R0: ReducerProtocol,
Expand Down Expand Up @@ -330,54 +311,12 @@ public enum ReducerBuilder<State, Action> {
)
}

@inlinable
public static func buildEither<R0: ReducerProtocol, R1: ReducerProtocol>(
first reducer: R0
) -> _Conditional<R0, R1>
where R0.State == State, R0.Action == Action {
.first(reducer)
}

@inlinable
public static func buildEither<R0: ReducerProtocol, R1: ReducerProtocol>(
second reducer: R1
) -> _Conditional<R0, R1>
where R1.State == State, R1.Action == Action {
.second(reducer)
}

@inlinable
public static func buildExpression<R: ReducerProtocol>(_ expression: R) -> R
where R.State == State, R.Action == Action {
expression
}

@inlinable
public static func buildFinalResult<R: ReducerProtocol>(_ reducer: R) -> R
where R.State == State, R.Action == Action {
reducer
}

@_disfavoredOverload
@inlinable
public static func buildFinalResult<R: ReducerProtocol>(_ reducer: R) -> Reduce<State, Action>
where R.State == State, R.Action == Action {
Reduce(reducer)
}

@inlinable
public static func buildLimitedAvailability<R: ReducerProtocol>(
_ wrapped: R
) -> _Optional<R>
where R.State == State, R.Action == Action {
_Optional(wrapped: wrapped)
}

@inlinable
public static func buildOptional<R: ReducerProtocol>(_ wrapped: R?) -> _Optional<R>
where R.State == State, R.Action == Action {
_Optional(wrapped: wrapped)
}
#endif

public enum _Conditional<First: ReducerProtocol, Second: ReducerProtocol>: ReducerProtocol
Expand All @@ -402,28 +341,6 @@ public enum ReducerBuilder<State, Action> {
}
}

public struct _Optional<Wrapped: ReducerProtocol>: ReducerProtocol {
@usableFromInline
let wrapped: Wrapped?

@usableFromInline
init(wrapped: Wrapped?) {
self.wrapped = wrapped
}

@inlinable
public func reduce(
into state: inout Wrapped.State, action: Wrapped.Action
) -> Effect<Wrapped.Action> {
switch wrapped {
case let .some(wrapped):
return wrapped.reduce(into: &state, action: action)
case .none:
return .none
}
}
}

public struct _Sequence<R0: ReducerProtocol, R1: ReducerProtocol>: ReducerProtocol
where R0.State == R1.State, R0.Action == R1.Action {
@usableFromInline
Expand Down Expand Up @@ -462,5 +379,3 @@ public enum ReducerBuilder<State, Action> {
}
}
}

public typealias ReducerBuilderOf<R: ReducerProtocol> = ReducerBuilder<R.State, R.Action>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
/// .ifLet(\.child, action: /Action.child)
/// }
/// ```
public struct CombineReducers<Reducers: ReducerProtocol>: ReducerProtocol {
public struct CombineReducers<State, Action, Reducers: ReducerProtocol>: ReducerProtocol
where State == Reducers.State, Action == Reducers.Action {
@usableFromInline
let reducers: Reducers

Expand All @@ -24,7 +25,7 @@ public struct CombineReducers<Reducers: ReducerProtocol>: ReducerProtocol {
/// - Parameter build: A reducer builder.
@inlinable
public init(
@ReducerBuilderOf<Reducers> _ build: () -> Reducers
@ReducerBuilder<State, Action> _ build: () -> Reducers
) {
self.init(internal: build())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ extension ReducerProtocol {
/// state.
/// - Returns: A reducer that combines the child reducer with the parent reducer.
@inlinable
public func forEach<ID: Hashable, Element: ReducerProtocol>(
_ toElementsState: WritableKeyPath<State, IdentifiedArray<ID, Element.State>>,
action toElementAction: CasePath<Action, (ID, Element.Action)>,
@ReducerBuilderOf<Element> _ element: () -> Element,
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,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> _ForEachReducer<Self, ID, Element> {
) -> _ForEachReducer<Self, ID, Element>
where ElementState == Element.State, ElementAction == Element.Action {
_ForEachReducer(
parent: self,
toElementsState: toElementsState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ extension ReducerProtocol {
/// present
/// - Returns: A reducer that combines the child reducer with the parent reducer.
@inlinable
public func ifCaseLet<Case: ReducerProtocol>(
_ toCaseState: CasePath<State, Case.State>,
action toCaseAction: CasePath<Action, Case.Action>,
@ReducerBuilderOf<Case> then case: () -> Case,
public func ifCaseLet<CaseState, CaseAction, Case: ReducerProtocol>(
_ toCaseState: CasePath<State, CaseState>,
action toCaseAction: CasePath<Action, CaseAction>,
@ReducerBuilder<CaseState, CaseAction> then case: () -> Case,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> _IfCaseLetReducer<Self, Case> {
) -> _IfCaseLetReducer<Self, Case>
where CaseState == Case.State, CaseAction == Case.Action {
.init(
parent: self,
child: `case`(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ extension ReducerProtocol {
/// state.
/// - Returns: A reducer that combines the child reducer with the parent reducer.
@inlinable
public func ifLet<Wrapped: ReducerProtocol>(
_ toWrappedState: WritableKeyPath<State, Wrapped.State?>,
action toWrappedAction: CasePath<Action, Wrapped.Action>,
@ReducerBuilderOf<Wrapped> then wrapped: () -> Wrapped,
public func ifLet<WrappedState, WrappedAction, Wrapped: ReducerProtocol>(
_ toWrappedState: WritableKeyPath<State, WrappedState?>,
action toWrappedAction: CasePath<Action, WrappedAction>,
@ReducerBuilder<WrappedState, WrappedAction> then wrapped: () -> Wrapped,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> _IfLetReducer<Self, Wrapped> {
) -> _IfLetReducer<Self, Wrapped>
where WrappedState == Wrapped.State, WrappedAction == Wrapped.Action {
.init(
parent: self,
child: wrapped(),
Expand Down
30 changes: 15 additions & 15 deletions Sources/RxComposableArchitecture/Reducer/Reducers/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
/// - toChildAction: A case path from parent action to a case containing child actions.
/// - child: A reducer that will be invoked with child actions against child state.
@inlinable
public init(
state toChildState: WritableKeyPath<ParentState, Child.State>,
action toChildAction: CasePath<ParentAction, Child.Action>,
@ReducerBuilderOf<Child> _ child: () -> Child
) {
public init<ChildState, ChildAction>(
state toChildState: WritableKeyPath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> _ child: () -> Child
) where ChildState == Child.State, ChildAction == Child.Action {
self.init(
toChildState: .keyPath(toChildState),
toChildAction: toChildAction,
Expand All @@ -156,14 +156,14 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
}

@inlinable
public init(
state toChildState: OptionalPath<ParentState, Child.State>,
action toChildAction: CasePath<ParentAction, Child.Action>,
@ReducerBuilderOf<Child> _ child: () -> Child,
public init<ChildState, ChildAction>(
state toChildState: OptionalPath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> _ child: () -> Child,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) {
) where ChildState == Child.State, ChildAction == Child.Action {
self.init(
toChildState: .optionalPath(toChildState, file: file, fileID: fileID, line: line),
toChildAction: toChildAction,
Expand Down Expand Up @@ -231,14 +231,14 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
/// - toChildAction: A case path from parent action to a case containing child actions.
/// - child: A reducer that will be invoked with child actions against child state.
@inlinable
public init(
state toChildState: CasePath<ParentState, Child.State>,
action toChildAction: CasePath<ParentAction, Child.Action>,
@ReducerBuilderOf<Child> _ child: () -> Child,
public init<ChildState, ChildAction>(
state toChildState: CasePath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> _ child: () -> Child,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) {
) where ChildState == Child.State, ChildAction == Child.Action {
self.init(
toChildState: .optionalPath(OptionalPath(toChildState), file: file, fileID: fileID, line: line),
toChildAction: toChildAction,
Expand Down
2 changes: 1 addition & 1 deletion Sources/RxComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public final class Store<State, Action> {
case let .send(action, originatingAction: nil):
runtimeWarn(
"""
"ViewStore.send" was called on a non-main thread with: \(debugCaseOutput(action))
"Store.send/ViewStore.send" was called on a non-main thread with: \(debugCaseOutput(action))
The "Store" class is not thread-safe, and so all interactions with an instance of \
"Store" (including all of its scopes and derived view stores) must be done on the main \
Expand Down
Loading

0 comments on commit db994cc

Please sign in to comment.