Skip to content

Commit

Permalink
Effect to EffectTask (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryu0118 committed May 25, 2023
1 parent 8b2889f commit a7d2d1e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Sources/MultiplayerFeature/PastGameRow.swift
Expand Up @@ -48,7 +48,7 @@ public struct PastGame: ReducerProtocol {

@Dependency(\.gameCenter) var gameCenter

public func reduce(into state: inout State, action: Action) -> Effect<Action, Never> {
public func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .delegate:
return .none
Expand Down
Expand Up @@ -28,7 +28,7 @@ public struct NotificationsAuthAlert: ReducerProtocol {

public init() {}

public func reduce(into state: inout State, action: Action) -> Effect<Action, Never> {
public func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .closeButtonTapped:
return .task { .delegate(.close) }.animation()
Expand Down
2 changes: 1 addition & 1 deletion Sources/SoloFeature/SoloView.swift
Expand Up @@ -25,7 +25,7 @@ public struct Solo: ReducerProtocol {

public init() {}

public func reduce(into state: inout State, action: Action) -> Effect<Action, Never> {
public func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .gameButtonTapped:
return .none
Expand Down
2 changes: 1 addition & 1 deletion Sources/TcaHelpers/FilterReducer.swift
Expand Up @@ -26,7 +26,7 @@ struct FilterReducer<Base: ReducerProtocol>: ReducerProtocol {
@inlinable
public func reduce(
into state: inout Base.State, action: Base.Action
) -> Effect<Base.Action, Never> {
) -> EffectTask<Base.Action> {
guard self.predicate(state, action) else { return .none }
return self.base.reduce(into: &state, action: action)
}
Expand Down
20 changes: 5 additions & 15 deletions Sources/TcaHelpers/OnChange.swift
Expand Up @@ -4,19 +4,15 @@ extension ReducerProtocol {
@inlinable
public func onChange<ChildState: Equatable>(
of toLocalState: @escaping (State) -> ChildState,
perform additionalEffects: @escaping (ChildState, inout State, Action) -> Effect<
Action, Never
>
perform additionalEffects: @escaping (ChildState, inout State, Action) -> EffectTask<Action>
) -> some ReducerProtocol<State, Action> {
self.onChange(of: toLocalState) { additionalEffects($1, &$2, $3) }
}

@inlinable
public func onChange<ChildState: Equatable>(
of toLocalState: @escaping (State) -> ChildState,
perform additionalEffects: @escaping (ChildState, ChildState, inout State, Action) -> Effect<
Action, Never
>
perform additionalEffects: @escaping (ChildState, ChildState, inout State, Action) -> EffectTask<Action>
) -> some ReducerProtocol<State, Action> {
ChangeReducer(base: self, toLocalState: toLocalState, perform: additionalEffects)
}
Expand All @@ -32,27 +28,21 @@ struct ChangeReducer<Base: ReducerProtocol, ChildState: Equatable>: ReducerProto

@usableFromInline
let perform:
(ChildState, ChildState, inout Base.State, Base.Action) -> Effect<
Base.Action, Never
>
(ChildState, ChildState, inout Base.State, Base.Action) -> EffectTask<Base.Action>

@usableFromInline
init(
base: Base,
toLocalState: @escaping (Base.State) -> ChildState,
perform: @escaping (ChildState, ChildState, inout Base.State, Base.Action) -> Effect<
Base.Action, Never
>
perform: @escaping (ChildState, ChildState, inout Base.State, Base.Action) -> EffectTask<Base.Action>
) {
self.base = base
self.toLocalState = toLocalState
self.perform = perform
}

@inlinable
public func reduce(into state: inout Base.State, action: Base.Action) -> Effect<
Base.Action, Never
> {
public func reduce(into state: inout Base.State, action: Base.Action) -> EffectTask<Base.Action> {
let previousLocalState = self.toLocalState(state)
let effects = self.base.reduce(into: &state, action: action)
let localState = self.toLocalState(state)
Expand Down
6 changes: 3 additions & 3 deletions Sources/TcaHelpers/OptionalPaths.swift
Expand Up @@ -213,7 +213,7 @@ public struct OptionalPathReducer<
@inlinable
public func reduce(
into state: inout Parent.State, action: Parent.Action
) -> Effect<Parent.Action, Never> {
) -> EffectTask<Parent.Action> {
return .merge(
self.reduceWrapped(into: &state, action: action),
self.parent.reduce(into: &state, action: action)
Expand All @@ -223,9 +223,9 @@ public struct OptionalPathReducer<
@usableFromInline
func reduceWrapped(
into state: inout Parent.State, action: Parent.Action
) -> Effect<Parent.Action, Never> {
) -> EffectTask<Parent.Action> {
guard let childAction = self.toChildAction.extract(from: action)
else { return Effect<Action, Never>.none }
else { return EffectTask<Parent.Action>.none }

guard var childState = self.toChildState.extract(from: state)
else {
Expand Down
Expand Up @@ -57,7 +57,7 @@ public struct UpgradeInterstitial: ReducerProtocol {

public init() {}

public func reduce(into state: inout State, action: Action) -> Effect<Action, Never> {
public func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
enum TimerID {}

switch action {
Expand Down

0 comments on commit a7d2d1e

Please sign in to comment.