This is a swift implementation of Buttons sample in Elm Official Guide.
For simplicity, commands and subscriptions are not included.(They are included in the v2.)
Also, incremental updates of views are not implemented.
(If you want to know them, please refer to referenced materials.)
I hope this will be a help to start learning The Elm Architecture with swift!
This corresponds to the Buttons sample in Elm Official Guide.
struct AppState {
// MODEL
var value: Int
// UPDATE
enum Message {
case increment
case decrement
}
mutating func update(_ message: Message) {
switch message {
case .increment:
value = value + 1
case .decrement:
value = value - 1
}
}
// VIEW
var viewController: ViewController<Message> {
return ._viewController(
.stackView(
views: [
.button(text: "-", onTap: .decrement),
.label(text: "\(value)"),
.button(text: "+", onTap: .increment)
],
axis: .vertical,
distriburtion: .fillEqually
)
)
}
}
- 2nd version
- App Architecture from objc.io
- book & video
- sample codes
- especially, Recordings-TEA & One-App-Eight-Architectures