[improvement] Notify: tsx & functional (#2810)

This commit is contained in:
neverland
2019-02-20 19:44:14 +08:00
committed by GitHub
parent 52e6fd2f0b
commit da91631b0d
10 changed files with 176 additions and 131 deletions

View File

@@ -1,4 +1,4 @@
import { RenderContext, VNodeData } from 'vue/types';
import Vue, { RenderContext, VNodeData } from 'vue';
type ObjectIndex = {
[key: string]: any;
@@ -21,7 +21,10 @@ const inheritKey = [
const mapInheritKey: ObjectIndex = { nativeOn: 'on' };
// inherit partial context, map nativeOn to on
export function inherit(context: Context, inheritListeners?: boolean): InheritContext {
export function inherit(
context: Context,
inheritListeners?: boolean
): InheritContext {
const result = inheritKey.reduce(
(obj, key) => {
if (context.data[key]) {
@@ -53,3 +56,18 @@ export function emit(context: Context, eventName: string, ...args: any[]) {
}
}
}
// mount functional component
export function mount(Component: any) {
const instance = new Vue({
el: document.createElement('div'),
props: Component.props,
render(h) {
return h(Component, { props: this.$props });
}
});
document.body.appendChild(instance.$el);
return instance;
}