var a = 0 //storing value
a = 5 // changing value assign to sth
a += 7 // mutating value to another
a // a = 12
struct Car {
let make: String
let model: String
var numberOfWheels: Int = 4
init(make: String, model: String) {
}
}
Car(make: "Honda", model: "HRV")
class UIView {
var userInteractionEnabled: Bool // 2^1
var opaque: Bool // 2^2
var hidden: Bool // 2^3
var autoresizesSubviews: Bool // 2^4
}
protocol ActionType {
init()
}
protocol StandardAction : ActionType {
var type: String { get }
var payload: Any? { get }
}
typealias Reducer = (State, ActionType) -> State
func reducer(state: State? = nil,
action: ActionType) -> State {
//do something with state
return //new state
}
Hold app state
Allow access state
Allow action to be dispatched
Register listeners and also unregister
protocol DisposableType {
var dispose: () -> () { get }
}
protocol StoreType {
associatedtype State
var getState: () -> State { get }
var dispatch: ActionType -> ActionType { get }
var subscribe: (State -> ()) ->
DisposableType { get }
}
store.dispatch(action)
func reducer(state, action) -> newState
store.subscribe { newState in
print(newState)
}