refactor(runtime-core): tweak component proxy implementation

This commit is contained in:
Evan You
2019-12-10 11:14:29 -05:00
parent d1527fbee4
commit c97d83aff2
14 changed files with 133 additions and 64 deletions

View File

@@ -310,7 +310,7 @@ describe('api: createApp', () => {
const handler = (app.config.warnHandler = jest.fn(
(msg, instance, trace) => {
expect(msg).toMatch(`Component is missing template or render function`)
expect(instance).toBe(ctx.renderProxy)
expect(instance).toBe(ctx.proxy)
expect(trace).toMatch(`Hello`)
}
))

View File

@@ -9,7 +9,7 @@ import { ComponentInternalInstance } from '../src/component'
describe('component: proxy', () => {
mockWarn()
it('data', () => {
test('data', () => {
const app = createApp()
let instance: ComponentInternalInstance
let instanceProxy: any
@@ -33,7 +33,7 @@ describe('component: proxy', () => {
expect(instance!.data.foo).toBe(2)
})
it('renderContext', () => {
test('renderContext', () => {
const app = createApp()
let instance: ComponentInternalInstance
let instanceProxy: any
@@ -57,7 +57,7 @@ describe('component: proxy', () => {
expect(instance!.renderContext.foo).toBe(2)
})
it('propsProxy', () => {
test('propsProxy', () => {
const app = createApp()
let instance: ComponentInternalInstance
let instanceProxy: any
@@ -83,7 +83,7 @@ describe('component: proxy', () => {
expect(`Attempting to mutate prop "foo"`).toHaveBeenWarned()
})
it('methods', () => {
test('public properties', () => {
const app = createApp()
let instance: ComponentInternalInstance
let instanceProxy: any
@@ -111,7 +111,7 @@ describe('component: proxy', () => {
expect(`Attempting to mutate public property "$data"`).toHaveBeenWarned()
})
it('sink', async () => {
test('sink', async () => {
const app = createApp()
let instance: ComponentInternalInstance
let instanceProxy: any
@@ -129,4 +129,46 @@ describe('component: proxy', () => {
expect(instanceProxy.foo).toBe(1)
expect(instance!.sink.foo).toBe(1)
})
test('has check', () => {
const app = createApp()
let instanceProxy: any
const Comp = {
render() {},
props: {
msg: String
},
data() {
return {
foo: 0
}
},
setup() {
return {
bar: 1
}
},
mounted() {
instanceProxy = this
}
}
app.mount(Comp, nodeOps.createElement('div'), { msg: 'hello' })
// props
expect('msg' in instanceProxy).toBe(true)
// data
expect('foo' in instanceProxy).toBe(true)
// renderContext
expect('bar' in instanceProxy).toBe(true)
// public properties
expect('$el' in instanceProxy).toBe(true)
// non-existent
expect('$foobar' in instanceProxy).toBe(false)
expect('baz' in instanceProxy).toBe(false)
// set non-existent (goes into sink)
instanceProxy.baz = 1
expect('baz' in instanceProxy).toBe(true)
})
})

View File

@@ -18,7 +18,7 @@ describe('directives', () => {
function assertBindings(binding: DirectiveBinding) {
expect(binding.value).toBe(count.value)
expect(binding.arg).toBe('foo')
expect(binding.instance).toBe(_instance && _instance.renderProxy)
expect(binding.instance).toBe(_instance && _instance.proxy)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}
@@ -151,7 +151,7 @@ describe('directives', () => {
function assertBindings(binding: DirectiveBinding) {
expect(binding.value).toBe(count.value)
expect(binding.arg).toBe('foo')
expect(binding.instance).toBe(_instance && _instance.renderProxy)
expect(binding.instance).toBe(_instance && _instance.proxy)
expect(binding.modifiers && binding.modifiers.ok).toBe(true)
}