Vam is a package for support MVI (Uni-Directional Architecture) in SwiftUI.
struct ContentView: VamView {
typealias Action = ContentViewAction
typealias Model = ContentViewModel
let action: ContentViewAction
@StateObject var model: ContentViewModel
var body: some View {
VStack {
Text("\(model.count)")
Button("Tap to increase count") {
action.increaseCount()
}
}
}
static func build() -> ContentView {
let model = ContentViewModel()
let action = ContentViewAction(model: model)
return .init(action: action, model: model)
}
}
class ContentViewAction: Action<ContentViewModel> {
func increaseCount() {
model?.count += 1
}
}
class ContentViewModel: Model {
@Published var count = 0
}