Swalt 0.2.0

Swalt 0.2.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布时间上次发布2015年6月
SPM支持 SPM

Mikkel Malmberg维护。



Swalt 0.2.0

由纯 Swift 2 实现的 Flux 集成。受 alt 启发。

用法

要运行示例项目,首先克隆仓库,然后从 Example 目录运行pod install

示例

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)
    }
}

待办事项

  • [ ] 快照(轻松序列化和恢复所有状态)

要求

安装

Swalt 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile:

pod "Swalt"

作者

Mikkel Malmberg, [email protected]

许可协议

Swalt 在 MIT 许可协议下提供。有关更多信息,请参阅 LICENSE 文件。