here’s my simple version of the redux pattern in swift.
import SwiftUI
public protocol ActionType {}
public protocol StateType {}
public protocol Store<T>:AnyObject, ObservableObject {
associatedtype T:StateType
func dispatch(_ action:ActionType) async
var state:T { get set }
var reducer:any Reducer<T> { get set }
}
public extension Store {
@MainActor
func dispatch(_ action:ActionType) {
self.state = reducer.reduce(action, self.state)
}
}
public protocol Reducer<T> {
associatedtype T:StateType
func reduce(_ action:ActionType, _ state:T) -> T
}
public protocol SceneLogic {
associatedtype SceneInteractor
associatedtype SceneStore:Store
var interactor:SceneInteractor { get set }
var store: any Store { get }
}