Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 1.6 KB

README.md

File metadata and controls

60 lines (42 loc) · 1.6 KB

SwiftElm

Reactive + Automaton + VTree in Swift, inspired by Elm.

Note: This library is only a 100 lines of code.

Example

// 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.

Acknowledgement

  • Evan Czaplicki: Creator of Elm

License

MIT