1 | import { assign, slice } from './util';
|
2 | import { createVNode } from './create-element';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export function cloneElement(vnode, props, children) {
|
12 | let normalizedProps = assign({}, vnode.props),
|
13 | key,
|
14 | ref,
|
15 | i;
|
16 | for (i in props) {
|
17 | if (i == 'key') key = props[i];
|
18 | else if (i == 'ref') ref = props[i];
|
19 | else normalizedProps[i] = props[i];
|
20 | }
|
21 |
|
22 | if (arguments.length > 2) {
|
23 | normalizedProps.children =
|
24 | arguments.length > 3 ? slice.call(arguments, 2) : children;
|
25 | }
|
26 |
|
27 | return createVNode(
|
28 | vnode.type,
|
29 | normalizedProps,
|
30 | key || vnode.key,
|
31 | ref || vnode.ref,
|
32 | null
|
33 | );
|
34 | }
|