1- /** @import { Effect, TemplateNode } from '#client' */
2- /** @import { Batch } from '../../reactivity/batch.js'; */
3- import { UNINITIALIZED } from '../../../../constants.js' ;
4- import { block , branch , pause_effect } from '../../reactivity/effects.js' ;
5- import { not_equal , safe_not_equal } from '../../reactivity/equality.js' ;
6- import { is_runes } from '../../context.js' ;
7- import { hydrate_next , hydrate_node , hydrating } from '../hydration.js' ;
8- import { create_text , should_defer_append } from '../operations.js' ;
9- import { current_batch } from '../../reactivity/batch.js' ;
1+ /** @import { TemplateNode } from '#client' */
2+ import { block } from '../../reactivity/effects.js' ;
3+ import { hydrate_next , hydrating } from '../hydration.js' ;
4+ import { BranchManager } from './branches.js' ;
105
116/**
127 * @template V
@@ -20,60 +15,9 @@ export function key(node, get_key, render_fn) {
2015 hydrate_next ( ) ;
2116 }
2217
23- var anchor = node ;
24-
25- /** @type {V | typeof UNINITIALIZED } */
26- var key = UNINITIALIZED ;
27-
28- /** @type {Effect } */
29- var effect ;
30-
31- /** @type {Effect } */
32- var pending_effect ;
33-
34- /** @type {DocumentFragment | null } */
35- var offscreen_fragment = null ;
36-
37- var changed = is_runes ( ) ? not_equal : safe_not_equal ;
38-
39- function commit ( ) {
40- if ( effect ) {
41- pause_effect ( effect ) ;
42- }
43-
44- if ( offscreen_fragment !== null ) {
45- // remove the anchor
46- /** @type {Text } */ ( offscreen_fragment . lastChild ) . remove ( ) ;
47-
48- anchor . before ( offscreen_fragment ) ;
49- offscreen_fragment = null ;
50- }
51-
52- effect = pending_effect ;
53- }
18+ var branches = new BranchManager ( node ) ;
5419
5520 block ( ( ) => {
56- if ( changed ( key , ( key = get_key ( ) ) ) ) {
57- var target = anchor ;
58-
59- var defer = should_defer_append ( ) ;
60-
61- if ( defer ) {
62- offscreen_fragment = document . createDocumentFragment ( ) ;
63- offscreen_fragment . append ( ( target = create_text ( ) ) ) ;
64- }
65-
66- pending_effect = branch ( ( ) => render_fn ( target ) ) ;
67-
68- if ( defer ) {
69- /** @type {Batch } */ ( current_batch ) . add_callback ( commit ) ;
70- } else {
71- commit ( ) ;
72- }
73- }
21+ branches . ensure ( get_key ( ) , render_fn ) ;
7422 } ) ;
75-
76- if ( hydrating ) {
77- anchor = hydrate_node ;
78- }
7923}
0 commit comments