Skip to content

Commit bb195b7

Browse files
committed
perf: unenumerable keys
1 parent 1feeb44 commit bb195b7

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

packages/runtime-vapor/src/dom/nodeDraft.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ export type MaybeNodeDraft<
1818
D extends NodeDraft = NodeDraft,
1919
> = N | D
2020

21-
function unenumerable(obj: any, key: string | symbol) {
22-
Object.defineProperty(obj, key, {
23-
enumerable: false,
24-
})
25-
}
26-
2721
type Constructor<T> = new (ref: NodeRef) => T
2822

2923
export class NodeRef<
@@ -50,6 +44,8 @@ export class NodeRef<
5044
throw new Error('HydrationNode has already been resolved')
5145
}
5246
;(Object.keys(this.ref) as Array<keyof NodeDraft>).forEach(key => {
47+
if (DraftSkippedKeys.has(key as string)) return
48+
5349
const newValue = this.draft![key]
5450
const oldValue = theRef[key]
5551
if (newValue !== oldValue) {
@@ -61,16 +57,18 @@ export class NodeRef<
6157
}
6258
}
6359

60+
const DraftSkippedKeys = new Set([
61+
'__v_nodeRef',
62+
'__v_parentNode',
63+
'__v_childNodes',
64+
])
65+
6466
export class NodeDraft {
6567
constructor(
6668
private __v_nodeRef: NodeRef,
6769
private __v_childNodes: NodeRef<false>[] = [],
6870
private __v_parentNode: NodeRef<false, ParentNode> | null = null,
69-
) {
70-
unenumerable(this, '__v_nodeRef')
71-
unenumerable(this, '__v_childNodes')
72-
unenumerable(this, '__v_parentNode')
73-
}
71+
) {}
7472

7573
get parentNode(): NodeRef<boolean, ParentNode> | null {
7674
return this.__v_parentNode
@@ -184,7 +182,7 @@ export function nodeDraftPatch(
184182
}
185183

186184
function _nodeDraftPatch(
187-
block: NodeRef[],
185+
block: readonly NodeRef[],
188186
parent: ParentNode,
189187
anchorIndex: number,
190188
) {
@@ -204,7 +202,9 @@ function _nodeDraftPatch(
204202
const childNodes = nodeRef.ref.childNodes
205203
if (childNodes.length) {
206204
let $anchor = (realNode as any).$anchor
207-
const theChildAnchorIndex = $anchor ? getNodeIndexOf(parent, $anchor) : 0
205+
const theChildAnchorIndex = $anchor
206+
? getNodeIndexOf(realNode as unknown as ParentNode, $anchor)
207+
: 0
208208

209209
_nodeDraftPatch(
210210
childNodes,

packages/runtime-vapor/src/dom/prop.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
isApplyingFallthroughProps,
2222
} from '../component'
2323
import {
24-
type NodeDraft,
24+
NodeDraft,
2525
type TextNodeDraft,
2626
type VaporNode,
2727
toNode,
@@ -171,7 +171,7 @@ export function setValue(
171171
return
172172
}
173173

174-
const isRealNode = el instanceof Node
174+
const isRealNode = !(el instanceof NodeDraft)
175175

176176
// store value as _value as well since
177177
// non-string values will be stringified.

0 commit comments

Comments
 (0)