isPureView()的Component的shouldUpdate()不会被调用
Opened this issue · 0 comments
niechaoqun9456 commented
bool isPureView() {
return protectedReducer == null &&
protectedEffect == null &&
protectedDependencies == null;
}
reducer、effect、dependencies都为null时,Compenent isPureView()=true。
@override
Widget buildComponent(
Store<Object> store,
Get<Object> getter, {
@required DispatchBus bus,
@required Enhancer<Object> enhancer,
}) {
/// Check bus: DispatchBusDefault(); enhancer: EnhancerDefault<Object>();
assert(bus != null && enhancer != null);
return protectedWrapper(
isPureView()
? _PureViewWidget<T>(
store: store,
viewBuilder: enhancer.viewEnhance(protectedView, this, store),
getter: getter,
bus: bus,
)
: ComponentWidget<T>(
component: this,
getter: _asGetter<T>(getter),
store: store,
key: key(getter()),
bus: bus,
enhancer: enhancer,
),
);
}
shouldUpdate只有当Component的isPureView()=false时才会起作用。
@override
void didUpdateWidget() {
final T now = state;
if (shouldUpdate(_latestState, now)) {
_widgetCache = null;
_latestState = now;
}
}
@override
void onNotify() {
final T now = state;
if (shouldUpdate(_latestState, now)) {
_widgetCache = null;
markNeedsBuild();
_latestState = now;
}
}
这样的话,每次State变化,pureView Component都会无条件buildView。
请问是有意这样设计的吗?如果是,这样设计的原因是什么?