@@ -96,29 +96,27 @@ export class BranchManager {
9696 * @param {(target: TemplateNode) => void } fn
9797 */
9898 ensure ( key , fn ) {
99- if ( should_defer_append ( ) ) {
100- var batch = /** @type {Batch } */ ( current_batch ) ;
99+ var batch = /** @type {Batch } */ ( current_batch ) ;
101100
102- if ( ! this . #onscreen. has ( key ) && ! this . #offscreen. has ( key ) ) {
103- var fragment = document . createDocumentFragment ( ) ;
104- var target = create_text ( ) ;
101+ if ( ! this . #onscreen. has ( key ) && ! this . #offscreen. has ( key ) ) {
102+ var fragment = document . createDocumentFragment ( ) ;
103+ var target = create_text ( ) ;
105104
106- fragment . append ( target ) ;
105+ fragment . append ( target ) ;
107106
108- this . #offscreen. set ( key , {
109- effect : branch ( ( ) => fn ( target ) ) ,
110- fragment
111- } ) ;
112- }
107+ this . #offscreen. set ( key , {
108+ effect : branch ( ( ) => fn ( target ) ) ,
109+ fragment
110+ } ) ;
111+ }
113112
114- this . #batches. set ( batch , key ) ;
113+ this . #batches. set ( batch , key ) ;
115114
115+ // TODO in the no-defer case, we could skip the offscreen step
116+ if ( should_defer_append ( ) ) {
116117 batch . add_callback ( this . #commit) ;
117118 } else {
118- this . #onscreen. set (
119- key ,
120- branch ( ( ) => fn ( this . #anchor) )
121- ) ;
119+ this . #commit( ) ;
122120 }
123121 }
124122}
0 commit comments