Latest 0.2.0
Homepage https://github.com/mikker/Swalt
License MIT
Platforms ios 8.0, osx 10.9, requires ARC
Dependencies Dispatcher
Authors

CI Status
Version
License
Platform

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

  • [x] Snapshots (easily serialize and restore all state)
  • [ ] Dictionaries are weird for states with all the typecasting.. Maybe structs instead?
  • [ ] More examples

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.

Latest podspec

{
    "name": "Swalt",
    "version": "0.2.0",
    "license": "MIT",
    "summary": "Flux implementation in pure Swift 2",
    "homepage": "https://github.com/mikker/Swalt",
    "authors": {
        "Mikkel Malmberg": "[email protected]"
    },
    "source": {
        "git": "https://github.com/mikker/Swalt.git",
        "tag": "0.2.0"
    },
    "social_media_url": "https://twitter.com/mikker",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "dependencies": {
        "Dispatcher": [
            "~> 0.1.0"
        ]
    },
    "source_files": "Pod/Classes/**/*",
    "requires_arc": true
}

Pin It on Pinterest

Share This