|
@@ -14,14 +14,7 @@ import {
|
|
|
createComponentInstance,
|
|
createComponentInstance,
|
|
|
setupStatefulComponent
|
|
setupStatefulComponent
|
|
|
} from './component'
|
|
} from './component'
|
|
|
-import {
|
|
|
|
|
- isString,
|
|
|
|
|
- isArray,
|
|
|
|
|
- isFunction,
|
|
|
|
|
- isObject,
|
|
|
|
|
- EMPTY_OBJ,
|
|
|
|
|
- EMPTY_ARR
|
|
|
|
|
-} from '@vue/shared'
|
|
|
|
|
|
|
+import { isString, isArray, EMPTY_OBJ, EMPTY_ARR } from '@vue/shared'
|
|
|
import {
|
|
import {
|
|
|
TEXT,
|
|
TEXT,
|
|
|
CLASS,
|
|
CLASS,
|
|
@@ -35,6 +28,7 @@ import { queueJob, queuePostFlushCb, flushPostFlushCbs } from './scheduler'
|
|
|
import { effect, stop, ReactiveEffectOptions } from '@vue/observer'
|
|
import { effect, stop, ReactiveEffectOptions } from '@vue/observer'
|
|
|
import { resolveProps } from './componentProps'
|
|
import { resolveProps } from './componentProps'
|
|
|
import { resolveSlots } from './componentSlots'
|
|
import { resolveSlots } from './componentSlots'
|
|
|
|
|
+import { ELEMENT, STATEFUL_COMPONENT, FUNCTIONAL_COMPONENT } from './shapeFlags'
|
|
|
|
|
|
|
|
const prodEffectOptions = {
|
|
const prodEffectOptions = {
|
|
|
scheduler: queueJob
|
|
scheduler: queueJob
|
|
@@ -108,7 +102,7 @@ export function createRenderer(options: RendererOptions) {
|
|
|
n2: VNode,
|
|
n2: VNode,
|
|
|
container: HostNode,
|
|
container: HostNode,
|
|
|
anchor?: HostNode,
|
|
anchor?: HostNode,
|
|
|
- optimized?: boolean
|
|
|
|
|
|
|
+ optimized: boolean = false
|
|
|
) {
|
|
) {
|
|
|
// patching & not same type, unmount old tree
|
|
// patching & not same type, unmount old tree
|
|
|
if (n1 != null && !isSameType(n1, n2)) {
|
|
if (n1 != null && !isSameType(n1, n2)) {
|
|
@@ -117,7 +111,7 @@ export function createRenderer(options: RendererOptions) {
|
|
|
n1 = null
|
|
n1 = null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const { type } = n2
|
|
|
|
|
|
|
+ const { type, shapeFlag } = n2
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
case Text:
|
|
case Text:
|
|
|
processText(n1, n2, container, anchor)
|
|
processText(n1, n2, container, anchor)
|
|
@@ -132,10 +126,14 @@ export function createRenderer(options: RendererOptions) {
|
|
|
processPortal(n1, n2, container, anchor, optimized)
|
|
processPortal(n1, n2, container, anchor, optimized)
|
|
|
break
|
|
break
|
|
|
default:
|
|
default:
|
|
|
- if (isString(type)) {
|
|
|
|
|
|
|
+ if (shapeFlag & ELEMENT) {
|
|
|
processElement(n1, n2, container, anchor, optimized)
|
|
processElement(n1, n2, container, anchor, optimized)
|
|
|
} else {
|
|
} else {
|
|
|
- if (__DEV__ && !isFunction(type) && !isObject(type)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ __DEV__ &&
|
|
|
|
|
+ !(shapeFlag & STATEFUL_COMPONENT) &&
|
|
|
|
|
+ !(shapeFlag & FUNCTIONAL_COMPONENT)
|
|
|
|
|
+ ) {
|
|
|
// TODO warn invalid node type
|
|
// TODO warn invalid node type
|
|
|
debugger
|
|
debugger
|
|
|
}
|
|
}
|
|
@@ -453,14 +451,14 @@ export function createRenderer(options: RendererOptions) {
|
|
|
const instance: ComponentInstance = (vnode.component = createComponentInstance(
|
|
const instance: ComponentInstance = (vnode.component = createComponentInstance(
|
|
|
Component
|
|
Component
|
|
|
))
|
|
))
|
|
|
- instance.update = effect(() => {
|
|
|
|
|
- if (!instance.vnode) {
|
|
|
|
|
|
|
+ instance.update = effect(function updateComponent() {
|
|
|
|
|
+ if (instance.vnode === null) {
|
|
|
// initial mount
|
|
// initial mount
|
|
|
instance.vnode = vnode
|
|
instance.vnode = vnode
|
|
|
resolveProps(instance, vnode.props, Component.props)
|
|
resolveProps(instance, vnode.props, Component.props)
|
|
|
resolveSlots(instance, vnode.children)
|
|
resolveSlots(instance, vnode.children)
|
|
|
// setup stateful
|
|
// setup stateful
|
|
|
- if (typeof Component === 'object') {
|
|
|
|
|
|
|
+ if (vnode.shapeFlag & STATEFUL_COMPONENT) {
|
|
|
setupStatefulComponent(instance)
|
|
setupStatefulComponent(instance)
|
|
|
}
|
|
}
|
|
|
const subTree = (instance.subTree = renderComponentRoot(instance))
|
|
const subTree = (instance.subTree = renderComponentRoot(instance))
|