1 |
|
2 |
|
3 | export default class VNode {
|
4 | tag: string | void;
|
5 | data: VNodeData | void;
|
6 | children: ?Array<VNode>;
|
7 | text: string | void;
|
8 | elm: Node | void;
|
9 | ns: string | void;
|
10 | context: Component | void;
|
11 | key: string | number | void;
|
12 | componentOptions: VNodeComponentOptions | void;
|
13 | componentInstance: Component | void;
|
14 | parent: VNode | void;
|
15 |
|
16 |
|
17 | raw: boolean;
|
18 | isStatic: boolean;
|
19 | isRootInsert: boolean;
|
20 | isComment: boolean;
|
21 | isCloned: boolean;
|
22 | isOnce: boolean;
|
23 | asyncFactory: Function | void;
|
24 | asyncMeta: Object | void;
|
25 | isAsyncPlaceholder: boolean;
|
26 | ssrContext: Object | void;
|
27 | fnContext: Component | void;
|
28 | fnOptions: ?ComponentOptions;
|
29 | devtoolsMeta: ?Object;
|
30 | fnScopeId: ?string;
|
31 |
|
32 | constructor (
|
33 | tag?: string,
|
34 | data?: VNodeData,
|
35 | children?: ?Array<VNode>,
|
36 | text?: string,
|
37 | elm?: Node,
|
38 | context?: Component,
|
39 | componentOptions?: VNodeComponentOptions,
|
40 | asyncFactory?: Function
|
41 | ) {
|
42 | this.tag = tag
|
43 | this.data = data
|
44 | this.children = children
|
45 | this.text = text
|
46 | this.elm = elm
|
47 | this.ns = undefined
|
48 | this.context = context
|
49 | this.fnContext = undefined
|
50 | this.fnOptions = undefined
|
51 | this.fnScopeId = undefined
|
52 | this.key = data && data.key
|
53 | this.componentOptions = componentOptions
|
54 | this.componentInstance = undefined
|
55 | this.parent = undefined
|
56 | this.raw = false
|
57 | this.isStatic = false
|
58 | this.isRootInsert = true
|
59 | this.isComment = false
|
60 | this.isCloned = false
|
61 | this.isOnce = false
|
62 | this.asyncFactory = asyncFactory
|
63 | this.asyncMeta = undefined
|
64 | this.isAsyncPlaceholder = false
|
65 | }
|
66 |
|
67 |
|
68 |
|
69 | get child (): Component | void {
|
70 | return this.componentInstance
|
71 | }
|
72 | }
|
73 |
|
74 | export const createEmptyVNode = (text: string = '') => {
|
75 | const node = new VNode()
|
76 | node.text = text
|
77 | node.isComment = true
|
78 | return node
|
79 | }
|
80 |
|
81 | export function createTextVNode (val: string | number) {
|
82 | return new VNode(undefined, undefined, undefined, String(val))
|
83 | }
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | export function cloneVNode (vnode: VNode): VNode {
|
90 | const cloned = new VNode(
|
91 | vnode.tag,
|
92 | vnode.data,
|
93 |
|
94 |
|
95 |
|
96 | vnode.children && vnode.children.slice(),
|
97 | vnode.text,
|
98 | vnode.elm,
|
99 | vnode.context,
|
100 | vnode.componentOptions,
|
101 | vnode.asyncFactory
|
102 | )
|
103 | cloned.ns = vnode.ns
|
104 | cloned.isStatic = vnode.isStatic
|
105 | cloned.key = vnode.key
|
106 | cloned.isComment = vnode.isComment
|
107 | cloned.fnContext = vnode.fnContext
|
108 | cloned.fnOptions = vnode.fnOptions
|
109 | cloned.fnScopeId = vnode.fnScopeId
|
110 | cloned.asyncMeta = vnode.asyncMeta
|
111 | cloned.isCloned = true
|
112 | return cloned
|
113 | }
|