- [ ] Fragment
- [x] multiple root nodes
- [x] all dynamic children
- - [ ] return `Node[]` for all dynamic children, instead of using `fragment` API
+ - [x] return `Node[]` for all dynamic children, instead of using `fragment` API
- [ ] Built-in Components
- [ ] Transition
- [ ] TransitionGroup
test('create fragment', () => {
const frag = fragment()
+
const root = frag()
- expect(root).toBeInstanceOf(DocumentFragment)
- expect(root.childNodes.length).toBe(0)
+ expect(root).toBeInstanceOf(Array)
+ expect(root.length).toBe(0)
- const div2 = frag()
- expect(div2).toBeInstanceOf(DocumentFragment)
- expect(div2).not.toBe(root)
+ const root2 = frag()
+ expect(root2).toBeInstanceOf(Array)
+ expect(root2).not.toBe(root)
})
})
import { isArray } from '@vue/shared'
export type Block = Node | Fragment | Block[]
+export type ParentBlock = ParentNode | Node[]
export type Fragment = { nodes: Block; anchor: Node }
export type BlockFn = (props?: any) => Block
// }
}
-export function append(parent: ParentNode, ...nodes: (Node | string)[]) {
- parent.append(...nodes)
+export function append(parent: ParentBlock, ...nodes: Node[]) {
+ if (parent instanceof Node) {
+ parent.append(...nodes)
+ } else if (isArray(parent)) {
+ parent.push(...nodes)
+ }
}
export function remove(block: Block, parent: ParentNode) {
}
}
-export function fragment(): () => DocumentFragment {
- return () => document.createDocumentFragment()
+export function fragment(): () => Node[] {
+ return () => []
}