“split” payload:“abcd” } a new state with [“a”,”b”,”c”,”d”] is created initial state : [] if type is “split” split the payload final state : [“a”,”b”,”c”,”d”]
type: 'Search', name: 'Apple' } Apple initial state : null if type is “Search” -> find in mem cache -> find in disk cache -> find in network -> update state final state : Apple
type : command • payload : parameter • class • val : read only • default constructor : auto defined properties class x extends State{ int num; int getNum()…. int setNum(int n)… } • seal class : • enum in Kotlin • restrict class hierarchy • sub class could have multiple instance
• Separation of concern • Pure function : less side effect • Finite number of states : predictable states • Could have sub-reducer ( combinedReducer) and dispatch to them. • “when” statement : like switch, but no cast • each line is an expression and can return value • work with Java
vm snapshot • could have sub state, let producer decides what to response and how to react • copy() ,equal() , hashCode(), toString() for free. • Destructuring Declarations • copy() : immutability • could have child state, let reducer decides what to react
if (type== action_add) return state using copy data class State(var num:Int) AppStore = Store.create(initial:State,reducers: Reducer[] ) 2:dispatch Subscribe 1:Hook 3:Return new Sate onStateChange