wip: fix more tests

This commit is contained in:
Evan You 2018-11-02 14:21:38 +09:00
parent f79f0e658b
commit 9d1f0f248d
4 changed files with 36 additions and 18 deletions

View File

@ -226,12 +226,16 @@ export function createRenderer(options: RendererOptions) {
if (vnode.flags & VNodeFlags.COMPONENT_STATEFUL_KEPT_ALIVE) { if (vnode.flags & VNodeFlags.COMPONENT_STATEFUL_KEPT_ALIVE) {
// kept-alive // kept-alive
activateComponentInstance(vnode, container, endNode) activateComponentInstance(vnode, container, endNode)
} else {
if (__COMPAT__) {
mountComponentInstance(vnode, container, isSVG, endNode)
} else { } else {
queueJob(() => { queueJob(() => {
mountComponentInstance(vnode, container, isSVG, endNode) mountComponentInstance(vnode, container, isSVG, endNode)
}, flushHooks) }, flushHooks)
} }
} }
}
function mountFunctionalComponent( function mountFunctionalComponent(
vnode: VNode, vnode: VNode,
@ -257,8 +261,7 @@ export function createRenderer(options: RendererOptions) {
queueJob(handle.runner) queueJob(handle.runner)
}) })
// we are using vnode.ref to store the functional component's update job const doMount = () => {
queueJob(() => {
handle.runner = autorun( handle.runner = autorun(
() => { () => {
if (handle.prevTree) { if (handle.prevTree) {
@ -270,6 +273,9 @@ export function createRenderer(options: RendererOptions) {
const nextTree = (handle.prevTree = current.children = renderFunctionalRoot( const nextTree = (handle.prevTree = current.children = renderFunctionalRoot(
current current
)) ))
queuePostCommitHook(() => {
current.el = nextTree.el
})
patch( patch(
prevTree as MountedVNode, prevTree as MountedVNode,
nextTree, nextTree,
@ -277,7 +283,6 @@ export function createRenderer(options: RendererOptions) {
current as MountedVNode, current as MountedVNode,
isSVG isSVG
) )
current.el = nextTree.el
if (__DEV__) { if (__DEV__) {
popWarningContext() popWarningContext()
} }
@ -289,8 +294,10 @@ export function createRenderer(options: RendererOptions) {
const subTree = (handle.prevTree = vnode.children = renderFunctionalRoot( const subTree = (handle.prevTree = vnode.children = renderFunctionalRoot(
vnode vnode
)) ))
mount(subTree, container, vnode as MountedVNode, isSVG, endNode) queuePostCommitHook(() => {
vnode.el = subTree.el as RenderNode vnode.el = subTree.el as RenderNode
})
mount(subTree, container, vnode as MountedVNode, isSVG, endNode)
if (__DEV__) { if (__DEV__) {
popWarningContext() popWarningContext()
} }
@ -300,7 +307,14 @@ export function createRenderer(options: RendererOptions) {
scheduler: queueUpdate scheduler: queueUpdate
} }
) )
}) }
// we are using vnode.ref to store the functional component's update job
if (__COMPAT__) {
doMount()
} else {
queueJob(doMount)
}
} }
function mountText( function mountText(
@ -1200,6 +1214,10 @@ export function createRenderer(options: RendererOptions) {
queuePostCommitHook(() => { queuePostCommitHook(() => {
vnode.el = instance.$vnode.el vnode.el = instance.$vnode.el
if (__COMPAT__) {
// expose __vue__ for devtools
;(vnode.el as any).__vue__ = instance
}
if (vnode.ref) { if (vnode.ref) {
vnode.ref($proxy) vnode.ref($proxy)
} }
@ -1219,11 +1237,6 @@ export function createRenderer(options: RendererOptions) {
endNode endNode
) )
if (__COMPAT__) {
// expose __vue__ for devtools
;(vnode.el as any).__vue__ = instance
}
instance._mounted = true instance._mounted = true
} }
}, },
@ -1435,12 +1448,19 @@ export function createRenderer(options: RendererOptions) {
container.vnode = null container.vnode = null
} }
} }
if (__COMPAT__) {
flushHooks()
return vnode && vnode.flags & VNodeFlags.COMPONENT_STATEFUL
? (vnode.children as ComponentInstance).$proxy
: null
} else {
return nextTick(() => { return nextTick(() => {
return vnode && vnode.flags & VNodeFlags.COMPONENT_STATEFUL return vnode && vnode.flags & VNodeFlags.COMPONENT_STATEFUL
? (vnode.children as ComponentInstance).$proxy ? (vnode.children as ComponentInstance).$proxy
: null : null
}) })
} }
}
return { render } return { render }
} }

View File

@ -63,9 +63,6 @@ export function dumpOps(): NodeOp[] {
} }
function createElement(tag: string): TestElement { function createElement(tag: string): TestElement {
if (nodeId === 5) {
throw new Error('foo')
}
const node: TestElement = { const node: TestElement = {
id: nodeId++, id: nodeId++,
type: NodeTypes.ELEMENT, type: NodeTypes.ELEMENT,

View File

@ -1,3 +1,4 @@
// temporary hack to wrap nodeOps so it works with time-slicing
import { NodeOps } from '@vue/runtime-core' import { NodeOps } from '@vue/runtime-core'
import { nodeOps } from '../../runtime-dom/src/nodeOps' import { nodeOps } from '../../runtime-dom/src/nodeOps'
import { nodeOps as testNodeOps } from '../../runtime-test/src/nodeOps' import { nodeOps as testNodeOps } from '../../runtime-test/src/nodeOps'

View File

@ -1,6 +1,6 @@
;(global as any).__COMPAT__ = true ;(global as any).__COMPAT__ = true
import Vue from '../src/index-compat' import Vue from '../src/index'
describe('2.x compat build', async () => { describe('2.x compat build', async () => {
test('should work', async () => { test('should work', async () => {