Skip to content

Commit

Permalink
Merge pull request #13 from Ryu0118/feature/rename-effecttask
Browse files Browse the repository at this point in the history
Rename EffectTask to SideEffect
  • Loading branch information
Ryu0118 authored Aug 23, 2023
2 parents c82ed80 + 930ea6c commit cba7fdd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct MyReducer {
case increment
case decrement
}
func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
switch action {
case .increment:
state.counter += 1
Expand Down Expand Up @@ -88,7 +88,7 @@ struct MyReducer {
var totalCalledCount = 0
}

func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
state.reducerState.totalCalledCount += 1
switch action {
case .increment:
Expand Down Expand Up @@ -142,7 +142,7 @@ struct MyReducer {

let authClient: AuthClient

func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
switch action {
case .login:
return .run { [email = state.email, password = state.password] send in
Expand All @@ -155,7 +155,7 @@ struct MyReducer {
}
}

func reduce(into state: inout State, action: ReducerAction) -> EffectTask<Self> {
func reduce(into state: inout State, action: ReducerAction) -> SideEffect<Self> {
switch action {
case let .loginResponse(result):
...
Expand Down
4 changes: 2 additions & 2 deletions Sources/SimplexArchitecture/Effect/EffectTask.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct EffectTask<Reducer: ReducerProtocol>: Sendable {
public struct SideEffect<Reducer: ReducerProtocol>: Sendable {
@usableFromInline
enum EffectKind: @unchecked Sendable {
case none
Expand All @@ -27,7 +27,7 @@ public struct EffectTask<Reducer: ReducerProtocol>: Sendable {
}
}

public extension EffectTask {
public extension SideEffect {
@inlinable
static var none: Self {
.init(effectKind: .none)
Expand Down
8 changes: 4 additions & 4 deletions Sources/SimplexArchitecture/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/// case countDown
/// }
///
/// func reduce(into state: inout State, action: Action) -> EffectTask<MyReducer> {
/// func reduce(into state: inout State, action: Action) -> SideEffect<MyReducer> {
/// switch action {
/// case .countUp:
/// state.counter += 1
Expand Down Expand Up @@ -77,7 +77,7 @@ public macro StoreBuilder<Reducer: ReducerProtocol>(reducer: Reducer) = #externa
/// let authRepository: AuthRepository
/// let selfRepository: SelfRepository
///
/// func reduce(into state: inout State, action: Action) -> EffectTask<MyReducer> {
/// func reduce(into state: inout State, action: Action) -> SideEffect<MyReducer> {
/// switch action {
/// case .someAction:
/// return .none
Expand Down Expand Up @@ -113,7 +113,7 @@ public macro StoreBuilder<Reducer: ReducerProtocol>(reducer: Reducer) = #externa
/// var counter: Int
/// }
///
/// func reduce(into state: inout State, action: Action) -> EffectTask<MyReducer> {
/// func reduce(into state: inout State, action: Action) -> SideEffect<MyReducer> {
/// switch action {
/// case .someAction:
/// state.reducerState.counter += 1
Expand Down Expand Up @@ -142,7 +142,7 @@ public macro ManualStoreBuilder<Reducer: ReducerProtocol>(reducer: Reducer.Type)
/// case someAction
/// }
///
/// func reduce(into state: inout State, action: Action) -> EffectTask<MyReducer> {
/// func reduce(into state: inout State, action: Action) -> SideEffect<MyReducer> {
/// switch action {
/// case .someAction:
/// state.reducerState.counter += 1
Expand Down
14 changes: 7 additions & 7 deletions Sources/SimplexArchitecture/ReducerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// case decrement
/// }
///
/// func reduce(into state: inout State, action: Action) -> EffectTask<MyReducer> {
/// func reduce(into state: inout State, action: Action) -> SideEffect<MyReducer> {
/// switch action {
/// case .increment:
/// state.counter += 1
Expand Down Expand Up @@ -53,7 +53,7 @@
/// var totalCalledCount = 0
/// }
///
/// func reduce(into state: inout State, action: Action) -> EffectTask<MyReducer> {
/// func reduce(into state: inout State, action: Action) -> SideEffect<MyReducer> {
/// state.reducerState.totalCalledCount += 1
/// switch action {
/// case .increment:
Expand Down Expand Up @@ -109,17 +109,17 @@ public protocol ReducerProtocol<Target> {
/// - Parameters:
/// - state: Current state of SimplexStoreView and ReducerState. ReducerState can be accessed from the `reducerState` property of State..
/// - action: An Action that can change the state of View and ReducerState.
/// - Returns: An `EffectTask` representing the side effects generated by the reducer.
func reduce(into state: inout State, action: Action) -> EffectTask<Self>
/// - Returns: An `SideEffect` representing the side effects generated by the reducer.
func reduce(into state: inout State, action: Action) -> SideEffect<Self>
/// Evolve the current state of SimplexStoreView to the next state.
///
/// - Parameters:
/// - state: Current state of SimplexStoreView and ReducerState. ReducerState can be accessed from the `reducerState` property of State..
/// - action: A ReducerAction that can change the state of View and ReducerState.
/// - Returns: An `EffectTask` representing the side effects generated by the reducer.
func reduce(into state: inout State, action: ReducerAction) -> EffectTask<Self>
/// - Returns: An `SideEffect` representing the side effects generated by the reducer.
func reduce(into state: inout State, action: ReducerAction) -> SideEffect<Self>
}

public extension ReducerProtocol where ReducerAction == Never {
func reduce(into state: inout State, action: ReducerAction) -> EffectTask<Self> {}
func reduce(into state: inout State, action: ReducerAction) -> SideEffect<Self> {}
}
16 changes: 8 additions & 8 deletions Sources/SimplexArchitecture/Send.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ extension Send {
extension Send {
@usableFromInline
func send(_ action: consuming Target.Reducer.Action) -> SendTask {
let effectTask = withLock {
let sideEffect = withLock {
reducer.reduce(into: &container, action: action)
}
if case .none = effectTask.kind {
if case .none = sideEffect.kind {
return .init(task: nil)
} else {
let tasks = runEffect(effectTask)
let tasks = runEffect(sideEffect)
return executeTasks(tasks)
}
}

@usableFromInline
func send(_ action: consuming Target.Reducer.ReducerAction) -> SendTask {
let effectTask = withLock {
let sideEffect = withLock {
reducer.reduce(into: &container, action: action)
}
if case .none = effectTask.kind {
if case .none = sideEffect.kind {
return .init(task: nil)
} else {
let tasks = runEffect(effectTask)
let tasks = runEffect(sideEffect)
return executeTasks(tasks)
}
}
Expand Down Expand Up @@ -104,8 +104,8 @@ extension Send {
return SendTask(task: task)
}

func runEffect(_ effectTask: borrowing EffectTask<Target.Reducer>) -> [Task<Void, Never>] {
switch effectTask.kind {
func runEffect(_ sideEffect: borrowing SideEffect<Target.Reducer>) -> [Task<Void, Never>] {
switch sideEffect.kind {
case .run(let priority, let operation, let `catch`):
let task = Task.detached(priority: priority ?? .medium) {
do {
Expand Down
8 changes: 4 additions & 4 deletions Tests/SimplexArchitectureTests/ReducerBuilderMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ReducerBuilderMacroTests: XCTestCase {
case test
}
func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
.none
}
}
Expand All @@ -31,7 +31,7 @@ final class ReducerBuilderMacroTests: XCTestCase {
case test
}
func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
.none
}
internal typealias State = StateContainer<TestView>
Expand All @@ -49,7 +49,7 @@ final class ReducerBuilderMacroTests: XCTestCase {
case test
}
public func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
public func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
.none
}
}
Expand All @@ -61,7 +61,7 @@ final class ReducerBuilderMacroTests: XCTestCase {
case test
}
public func reduce(into state: inout State, action: Action) -> EffectTask<Self> {
public func reduce(into state: inout State, action: Action) -> SideEffect<Self> {
.none
}
public typealias State = StateContainer<TestView>
Expand Down

0 comments on commit cba7fdd

Please sign in to comment.