chore: notes

This commit is contained in:
Evan You 2024-12-04 15:24:52 +08:00
parent b1b3baeb6e
commit 59b1aeda51
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
3 changed files with 8 additions and 15 deletions

View File

@ -24,6 +24,7 @@ export function isBlock(val: NonNullable<unknown>): val is Block {
}
/*! #__NO_SIDE_EFFECTS__ */
// TODO this should be optimized away
export function normalizeBlock(block: Block): Node[] {
const nodes: Node[] = []
if (block instanceof Node) {

View File

@ -1,6 +1,5 @@
import { remove } from '@vue/shared'
import type { DelegatedHandler } from './dom/event'
import type { Data } from '@vue/runtime-shared'
export enum MetadataKind {
prop,
@ -8,7 +7,7 @@ export enum MetadataKind {
}
export type ComponentMetadata = [
props: Data,
props: Record<string, any>,
events: Record<string, DelegatedHandler[]>,
]

View File

@ -4,17 +4,6 @@ import { setText } from './prop'
import { type Block, normalizeBlock } from '../block'
import { isVaporComponent } from '../component'
// export function insert(
// block: Block,
// parent: ParentNode,
// anchor: Node | null = null,
// ): void {
// const nodes = normalizeBlock(block)
// for (let i = 0; i < nodes.length; i++) {
// parent.insertBefore(nodes[i], anchor)
// }
// }
export function insert(
block: Block,
parent: ParentNode,
@ -28,15 +17,18 @@ export function insert(
for (let i = 0; i < block.length; i++) {
insert(block[i], parent, anchor)
}
} else if (block) {
} else {
// fragment
insert(block.nodes, parent, anchor)
}
}
export function prepend(parent: ParentNode, ...blocks: Block[]): void {
parent.prepend(...normalizeBlock(blocks))
const anchor = parent.firstChild
for (const b of blocks) insert(b, parent, anchor)
}
// TODO optimize
export function remove(block: Block, parent: ParentNode): void {
const nodes = normalizeBlock(block)
for (let i = 0; i < nodes.length; i++) {
@ -44,6 +36,7 @@ export function remove(block: Block, parent: ParentNode): void {
}
}
// TODO optimize
export function createTextNode(values?: any[] | (() => any[])): Text {
// eslint-disable-next-line no-restricted-globals
const node = document.createTextNode('')