feat: Refactors / moves into individual files, wip.

This commit is contained in:
2024-05-30 19:52:15 -04:00
parent 11ddfb04c3
commit bd0f90894f
6 changed files with 202 additions and 104 deletions

View File

@@ -0,0 +1,32 @@
import ComposableArchitecture
import Foundation
@usableFromInline
enum SetAction<State, Action, Value> {
case operation(f: (inout State, Value) -> Effect<Action>)
case keyPath(WritableKeyPath<State, Value>, effect: Effect<Action>)
case optionalKeyPath(WritableKeyPath<State, Value?>, effect: Effect<Action>)
@usableFromInline
func callAsFunction(state: inout State, value: Value) -> Effect<Action> {
switch self {
case let .operation(f: f):
return f(&state, value)
case let .keyPath(keyPath, effect):
state[keyPath: keyPath] = value
return effect
case let .optionalKeyPath(keyPath, effect):
state[keyPath: keyPath] = value
return effect
}
}
@usableFromInline
static func operation(_ f: @escaping (inout State, Value) -> Void) -> Self {
.operation(f: { state, value in
f(&state, value)
return .none
})
}
}