Swalt 0.2.0

Swalt 0.2.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2015
SPMSupports SPM

Maintained by Mikkel Malmberg.



Swalt 0.2.0

A minimal Flux implementation written in pure Swift 2. Inspired by alt.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Example

import UIKit
import Swalt

struct CounterActions {
    static let Increment = Action("increment")
}

class ClicksStore: Store {
    override var initialState: State {
        return ["count": 0]
    }

    required init(_ swalt: Swalt) {
        super.init(swalt)

        bindAction(CounterActions.Increment) { _payload in
            let current = self.state["count"]! as! Int
            self.state = ["count": current + 1]
        }
    }
}

class Flux: Swalt {
    static let shared = Flux()

    override init() {
        super.init()
        addStore(ClicksStore)
    }
}

class ViewController: UIViewController {

    @IBOutlet weak var countLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        Flux.shared.getStore(ClicksStore).listen { state in
            let count = state["count"] as! Int
            self.countLabel.text = String(count)
        }
    }

    @IBAction func doIt() {
        Swalt.instance.dispatch(CounterActions.Increment, payload: nil)
    }
}

Todo

  • [ ] Snapshots (easily serialize and restore all state)

Requirements

Installation

Swalt is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Swalt"

Author

Mikkel Malmberg, [email protected]

License

Swalt is available under the MIT license. See the LICENSE file for more info.