2018-09-20 03:19:25 +00:00
|
|
|
import {
|
|
|
|
h,
|
|
|
|
render,
|
2018-09-20 03:43:27 +00:00
|
|
|
nextTick,
|
2018-09-20 03:19:25 +00:00
|
|
|
Component,
|
|
|
|
createComponentInstance
|
|
|
|
} from '@vue/renderer-dom'
|
2018-09-20 01:52:24 +00:00
|
|
|
|
2018-10-09 17:59:30 +00:00
|
|
|
// Note: typing for this is intentionally loose, as it will be using 2.x types.
|
|
|
|
class Vue extends Component {
|
2018-09-20 03:19:25 +00:00
|
|
|
static h = h
|
|
|
|
static render = render
|
2018-09-20 03:43:27 +00:00
|
|
|
static nextTick = nextTick
|
2018-09-20 01:52:24 +00:00
|
|
|
|
2018-10-09 17:59:30 +00:00
|
|
|
constructor(options: any) {
|
2018-09-20 03:19:25 +00:00
|
|
|
super()
|
|
|
|
if (!options) {
|
|
|
|
return
|
2018-09-20 01:52:24 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 06:11:05 +00:00
|
|
|
// in compat mode, h() can take an options object and will convert it
|
|
|
|
// to a 3.x class-based component.
|
2018-09-20 03:19:25 +00:00
|
|
|
const vnode = h(options)
|
2018-09-20 06:11:05 +00:00
|
|
|
// the component class is cached on the options object as ._normalized
|
2018-09-20 03:19:25 +00:00
|
|
|
const instance = createComponentInstance(vnode, options._normalized, null)
|
2018-09-20 06:11:05 +00:00
|
|
|
// set the instance on the vnode before mounting.
|
|
|
|
// the mount function will skip creating a new instance if it finds an
|
|
|
|
// existing one.
|
2018-09-20 03:19:25 +00:00
|
|
|
vnode.children = instance
|
|
|
|
|
|
|
|
function mount(el: any) {
|
2018-09-20 03:43:27 +00:00
|
|
|
const dom = typeof el === 'string' ? document.querySelector(el) : el
|
2018-09-20 03:19:25 +00:00
|
|
|
render(vnode, dom)
|
|
|
|
return instance.$proxy
|
|
|
|
}
|
2018-09-20 01:52:24 +00:00
|
|
|
|
2018-09-20 03:19:25 +00:00
|
|
|
if (options.el) {
|
|
|
|
return mount(options.el)
|
|
|
|
} else {
|
|
|
|
;(instance as any).$mount = mount
|
|
|
|
return instance.$proxy
|
2018-09-20 01:52:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 17:59:30 +00:00
|
|
|
interface Vue {
|
|
|
|
$mount(el: any): any
|
2018-10-08 22:09:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 01:52:24 +00:00
|
|
|
export default Vue
|
2018-10-03 14:30:31 +00:00
|
|
|
export * from '@vue/renderer-dom'
|