TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2015 |
SPMSupports SPM | ✗ |
Maintained by Francis Chong.
Another Flux implementation for Swift. It provides concept of “one-way data flow” with type-safe modules by Swift language.
Action
.struct TodoActions {
struct Create : Action {
let title : String
}
}
Store
protocol with a typealiase State
Alt.getStore(YourStore.self)
to get a singleton instance of the storeself.emitChange()
to notify listeners about change of states in Store
class TodoStore : Store {
// define a typealias for the state of the model
typealias State = [Todo]
// and add a property of the State
var state : State!
// Set the initial state of the Store
static func getInitialState() -> State {
return []
}
required init() {
self.bindAction(TodoActions.Create.self, handler: self.onCreate)
// alternatively, bind action with a block
self.bindAction(TodoActions.Create.self) { [weak self] (action) -> () in
self?.state.append(Todo(title: action.title))
}
}
private func onCreate(action: TodoActions.Create) {
self.state.append(Todo(title: action.title))
self.emitChange()
}
}
store.state
change by Store.listen()
self.todoStore.listen { (state) -> (Void) in
self.tableView.reloadData()
}
TodoActions.Create(title: "New ToDo").dispatch()
Alt is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Alt"
Francis Chong, [email protected]
Alt is available under the MIT license. See the LICENSE file for more info.