holajiawei / notes

simple notes repo
2 stars 0 forks source link

Redux Reducer #1

Open holajiawei opened 6 years ago

holajiawei commented 6 years ago

Structuring Reducers notes

Structuring Reducers

  1. Side effects like mutation or asynchronous behavior will cause time travel to alter behavior between steps, breaking the application.
  2. 看了下redux-react中shallowEqual的判断,确实依赖state的immutable性质,否则第一个referenceEqual就通过不了。
  3. state通用的数据类型 domain data、app state 、ui state
  4. Functions can contain conditional logic other than switch statements, functions can be composed to wrap each other, and functions can call other functions. Reducer pure function
  5. Since immutable data updates require all ancestors in the state tree to be copied and updated as well, and new object references will cause connected UI components to re-render, an update to a deeply nested data object could force totally unrelated UI components to re-render even if the data they're displaying hasn't actually changed. 所以React-redux在做绑定的时候connect对mapState做了简单地计算,比较前后内部state是否一致.
  6. Reusing reducer logic maybe HOC (reducer) => { another reducer}
  7. imuutable function builts in JS:slice、concat、assign、fronze
holajiawei commented 6 years ago
  1. 要避免state浅拷贝的情况,虽然生成了新对象,但新对象引用的对象内部发生了修改,从而还是修改了原state