Skip to content

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

License

Notifications You must be signed in to change notification settings

inamiy/SwiftElm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ad14230 · Feb 13, 2019

History

21 Commits
Feb 13, 2019
Feb 13, 2019
Feb 27, 2017
May 14, 2017
May 14, 2017
Feb 13, 2019
May 17, 2017
Dec 7, 2016
Feb 26, 2017
May 14, 2017
Feb 13, 2019
Feb 13, 2019
May 17, 2017
Dec 7, 2016
May 14, 2017

Repository files navigation

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

Releases

No releases published

Packages

No packages published