react-redux 6.0
Q1:我想知道lastState === state
中的什么时候成立,如果状态不变,我认为它不会在Provider.js中调用setState
Q2:除第一次外,在store !== lastStore
中会为真
Provider.js
this.setState(providerState => {
// If the value is the same, skip the unnecessary state update.
if (providerState.storeState === newStoreState) {
return null
}
return { storeState: newStoreState }
})
})
connectAdvanced.js
return function selectDerivedProps(
state,
props,
store,
selectorFactoryOptions
) {
if (pure && lastProps === props && lastState === state) {
return lastDerivedProps
}
if (
store !== lastStore ||
lastSelectorFactoryOptions !== selectorFactoryOptions
) {
lastStore = store
...
}