@@ -5,9 +5,12 @@ import {
55 mountComponent ,
66 unmountComponent ,
77} from './component'
8- import { createComment , createTextNode } from './dom/node'
9- import { EffectScope , pauseTracking , resetTracking } from '@vue/reactivity'
108import { isHydrating } from './dom/hydration'
9+ import {
10+ type DynamicFragment ,
11+ type VaporFragment ,
12+ isFragment ,
13+ } from './fragment'
1114
1215export type Block =
1316 | Node
@@ -18,72 +21,6 @@ export type Block =
1821
1922export type BlockFn = ( ...args : any [ ] ) => Block
2023
21- export class VaporFragment {
22- nodes : Block
23- target ?: ParentNode | null
24- targetAnchor ?: Node | null
25- anchor ?: Node
26- insert ?: ( parent : ParentNode , anchor : Node | null ) => void
27- remove ?: ( parent ?: ParentNode ) => void
28- getNodes ?: ( ) => Block
29-
30- constructor ( nodes : Block ) {
31- this . nodes = nodes
32- }
33- }
34-
35- export class DynamicFragment extends VaporFragment {
36- anchor : Node
37- scope : EffectScope | undefined
38- current ?: BlockFn
39- fallback ?: BlockFn
40-
41- constructor ( anchorLabel ?: string ) {
42- super ( [ ] )
43- this . anchor =
44- __DEV__ && anchorLabel ? createComment ( anchorLabel ) : createTextNode ( )
45- }
46-
47- update ( render ?: BlockFn , key : any = render ) : void {
48- if ( key === this . current ) {
49- return
50- }
51- this . current = key
52-
53- pauseTracking ( )
54- const parent = this . anchor . parentNode
55-
56- // teardown previous branch
57- if ( this . scope ) {
58- this . scope . stop ( )
59- parent && remove ( this . nodes , parent )
60- }
61-
62- if ( render ) {
63- this . scope = new EffectScope ( )
64- this . nodes = this . scope . run ( render ) || [ ]
65- if ( parent ) insert ( this . nodes , parent , this . anchor )
66- } else {
67- this . scope = undefined
68- this . nodes = [ ]
69- }
70-
71- if ( this . fallback && ! isValidBlock ( this . nodes ) ) {
72- parent && remove ( this . nodes , parent )
73- this . nodes =
74- ( this . scope || ( this . scope = new EffectScope ( ) ) ) . run ( this . fallback ) ||
75- [ ]
76- parent && insert ( this . nodes , parent , this . anchor )
77- }
78-
79- resetTracking ( )
80- }
81- }
82-
83- export function isFragment ( val : NonNullable < unknown > ) : val is VaporFragment {
84- return val instanceof VaporFragment
85- }
86-
8724export function isBlock ( val : NonNullable < unknown > ) : val is Block {
8825 return (
8926 val instanceof Node ||
0 commit comments