(component, isForce = false)
| 223 | } |
| 224 | |
| 225 | export function updateComponent (component, isForce = false) { |
| 226 | let vnode = component.vnode |
| 227 | let dom = vnode.dom |
| 228 | const props = component.props |
| 229 | let state = component.getState() |
| 230 | const context = component.context |
| 231 | const prevProps = component.prevProps || props |
| 232 | const prevState = component.prevState || component.state |
| 233 | const prevContext = component.prevContext || context |
| 234 | |
| 235 | const stateFromProps = callGetDerivedStateFromProps(props, state, component) |
| 236 | |
| 237 | if (!isUndefined(stateFromProps)) { |
| 238 | state = stateFromProps |
| 239 | } |
| 240 | |
| 241 | component.props = prevProps |
| 242 | component.context = prevContext |
| 243 | let skip = false |
| 244 | const onSCU = props.onShouldComponentUpdate |
| 245 | if ( |
| 246 | !isForce && |
| 247 | ( |
| 248 | (isFunction(component.shouldComponentUpdate) && |
| 249 | callShouldComponentUpdate(props, state, context, component) === false) || |
| 250 | (isFunction(onSCU) && onSCU(prevProps, props) === false) |
| 251 | ) |
| 252 | ) { |
| 253 | skip = true |
| 254 | } else if (!hasNewLifecycle(component) && isFunction(component.componentWillUpdate)) { |
| 255 | errorCatcher(() => { |
| 256 | component.componentWillUpdate(props, state, context) |
| 257 | }, component) |
| 258 | } |
| 259 | |
| 260 | if (!isUndefined(stateFromProps)) { |
| 261 | component.state = stateFromProps |
| 262 | } |
| 263 | |
| 264 | component.props = props |
| 265 | component.state = state |
| 266 | component.context = context |
| 267 | component._dirty = false |
| 268 | if (!skip) { |
| 269 | const lastRendered = component._rendered |
| 270 | const rendered = renderComponent(component) |
| 271 | rendered.parentVNode = vnode |
| 272 | const childContext = getChildContext(component, context) |
| 273 | const snapshot = callGetSnapshotBeforeUpdate(prevProps, prevState, component) |
| 274 | let parentDom = lastRendered.dom && lastRendered.dom.parentNode |
| 275 | if (isArray(lastRendered)) { |
| 276 | const hostNode = getFragmentHostNode(lastRendered) |
| 277 | if (hostNode != null) { |
| 278 | parentDom = (lastRendered as any).dom = hostNode.parentNode |
| 279 | } |
| 280 | } |
| 281 | dom = vnode.dom = patch(lastRendered, rendered, parentDom || null, childContext) |
| 282 | component._rendered = rendered |
no test coverage detected