前言
在开启本篇的正文之前我们先做一个实验,我们来定义一个空的 Action
,也就是在 Reducer
中。这个 Action
什么也不做。然后我们在页面的Widget
的build
方法打印对应的信息在页面,通过响应按钮点击来调度这个 Action
。大家猜猜依赖于 Store
的组件是否会被重建(Rebuild
)?
我们先看一下运行结果。
答案是:**如果你什么都不做那就会重建。**这肯定会让我们觉得奇怪,为什么状态数据没有改变,还是会做重建操作呢?
Redux 刷新机制
要回答上面的问题,我们就需要了解 Redux 的刷新机制,来看StoreConnector
源码中的定义:
Every time the store changes, the Widget will be rebuilt. As a performance optimization, the Widget can be rebuilt only when the [ViewModel] changes. In order for this to work correctly, you must implement [==] and [hashCode] for the [ViewModel], and set the [di