13. Three Principles
Single source of truth
所有的狀態、資料皆來自store
State is read-only
所有的狀態改變都由dispatch action來完成
Changes are made with pure functions
由pure reducer 處理action,決定下一個state
14. Pure and impure function
不該改變傳入的參數
不該呼叫non-pure function
不該有side effect(call API, change route)
Swift本身的型別限制幫了一些忙
// Pure function
func square(x) {
return x * x
}
func squareAll(items: [Int]) {
return items.map(square)
}
15. ReSwift
Redux-like implementation of the unidirectional data flow architecture in Swift
ReSwift-Router
處理App中個頁面navigation的state
ReSwift-Recorder
記下Action的時間軸,方便做到time travel