( vnode: FullComponent, parentContext: ParentContext, parentComponent )
| 92 | } |
| 93 | |
| 94 | export function mountComponent ( |
| 95 | vnode: FullComponent, |
| 96 | parentContext: ParentContext, |
| 97 | parentComponent |
| 98 | ) { |
| 99 | const ref = vnode.ref |
| 100 | if (vnode.type.prototype && vnode.type.prototype.render) { |
| 101 | const context = getContextByContextType(vnode, parentContext) |
| 102 | vnode.component = new vnode.type(vnode.props, context) |
| 103 | } else { |
| 104 | const c = new Component(vnode.props, parentContext) |
| 105 | c.render = () => vnode.type.call(c, c.props, c.context) |
| 106 | vnode.component = c |
| 107 | } |
| 108 | const component = vnode.component |
| 109 | component.vnode = vnode |
| 110 | if (isComponent(parentComponent)) { |
| 111 | component._parentComponent = parentComponent as any |
| 112 | } |
| 113 | const newState = callGetDerivedStateFromProps(vnode.props, component.state, component) |
| 114 | if (!isUndefined(newState)) { |
| 115 | component.state = newState |
| 116 | } |
| 117 | if (!hasNewLifecycle(component) && isFunction(component.componentWillMount)) { |
| 118 | errorCatcher(() => { |
| 119 | (component as any).componentWillMount() |
| 120 | }, component) |
| 121 | component.state = component.getState() |
| 122 | component.clearCallBacks() |
| 123 | } |
| 124 | component._dirty = false |
| 125 | const rendered = renderComponent(component) |
| 126 | rendered.parentVNode = vnode |
| 127 | component._rendered = rendered |
| 128 | if (!isNullOrUndef(ref)) { |
| 129 | Ref.attach(vnode, ref, vnode.dom as Element) |
| 130 | } |
| 131 | const dom = (vnode.dom = mountVNode( |
| 132 | rendered, |
| 133 | getChildContext(component, parentContext), |
| 134 | component |
| 135 | ) as Element) |
| 136 | invokeEffects(component) |
| 137 | if (isFunction(component.componentDidMount)) { |
| 138 | readyComponents.push(component) |
| 139 | } |
| 140 | component._disable = false |
| 141 | return dom |
| 142 | } |
| 143 | |
| 144 | export function getChildContext (component, context = EMPTY_OBJ) { |
| 145 | if (isFunction(component.getChildContext)) { |
no test coverage detected