Skip to content

Commit 98cb876

Browse files
committed
merge createVNode into createElement
1 parent 411c60e commit 98cb876

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

src/component.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { commitRoot } from './diff/commit';
22
import options from './options';
3-
import { createVNode, Fragment } from './create-element';
3+
import { createElement, Fragment } from './create-element';
44
import { patch } from './diff/patch';
55
import { DIRTY_BIT, FORCE_UPDATE, MODE_UNMOUNTING } from './constants';
66
import { getParentDom } from './tree';
@@ -93,13 +93,8 @@ Component.prototype.render = Fragment;
9393
*/
9494
function rerender(internal) {
9595
if (~internal.flags & MODE_UNMOUNTING && internal.flags & DIRTY_BIT) {
96-
const vnode = createVNode(
97-
internal.type,
98-
internal.props,
99-
internal.key, // @TODO we shouldn't need to actually pass these
100-
internal.ref, // since the mode flag should bypass key/ref handling
101-
0
102-
);
96+
const vnode = createElement(internal.type, internal.props);
97+
vnode.props = internal.props;
10398

10499
patch(internal, vnode, getParentDom(internal));
105100
commitRoot(internal);

src/create-element.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,15 @@ export function createElement(type, props, children) {
3434
normalizedProps.children = children;
3535
}
3636

37-
return createVNode(type, normalizedProps, key, ref, 0);
38-
}
39-
40-
/**
41-
* Create a VNode (used internally by Preact)
42-
* @param {import('./internal').VNode["type"]} type The node name or Component
43-
* Constructor for this virtual node
44-
* @param {object | string | number | null} props The properties of this virtual node.
45-
* If this virtual node represents a text node, this is the text of the node (string or number).
46-
* @param {string | number | null} key The key for this virtual node, used when
47-
* diffing it against its children
48-
* @param {import('./internal').VNode["ref"]} ref The ref property that will
49-
* receive a reference to its created child
50-
* @returns {import('./internal').VNode}
51-
*/
52-
export function createVNode(type, props, key, ref, original) {
5337
// V8 seems to be better at detecting type shapes if the object is allocated from the same call site
5438
// Do not inline into createElement and coerceToVNode!
5539
const vnode = {
5640
type,
57-
props,
41+
props: normalizedProps,
5842
key,
5943
ref,
6044
constructor: undefined,
61-
_vnodeId: original || ++vnodeId
45+
_vnodeId: ++vnodeId
6246
};
6347

6448
if (options.vnode != null) options.vnode(vnode);
@@ -77,7 +61,7 @@ export function normalizeToVNode(childVNode) {
7761
}
7862
if (type === 'object') {
7963
if (Array.isArray(childVNode)) {
80-
return createVNode(Fragment, { children: childVNode }, null, null, 0);
64+
return createElement(Fragment, null, childVNode);
8165
}
8266
} else if (type !== 'string' && type !== 'function') {
8367
return String(childVNode);

0 commit comments

Comments
 (0)