Reactive + Automaton + VTree in Swift, inspired by Elm.
Note: This library is only a 100 lines of code.
// main.swift
import UIKit
import VTree
import SwiftElm
enum Msg: AutoMessage {
case increment
case decrement
}
typealias Model = Int
func update(state: Model, input: Msg) -> Model? {
switch input {
case .increment:
return state + 1
case .decrement:
return state - 1
}
}
func view(_ model: Model) -> VView<Msg> {
return VView(children: [
*VLabel(text: "\(model)"),
*VButton(title: "+", handlers: [.touchUpInside : .increment]),
*VButton(title: "-", handlers: [.touchUpInside : .decrement]),
])
}
// App main entrypoint (using `UIApplicationMain`).
appMain {
return Program(model: 0, update: update, view: view)
}
Please see Demo Projects for more information.
Metaprogramming with Sourcery
SwiftElm uses Sourcery as Swift template metaprogramming engine to cover transcripting that elm-lang/core does when converting enum MyMsg
to JavaScript.
Please see VTree/README.md for more information.
- Evan Czaplicki: Creator of Elm