@@ -49,11 +49,11 @@ export function boundary(node, props, children) {
49
49
}
50
50
51
51
export class Boundary {
52
- pending = false ;
53
-
54
52
/** @type {Boundary | null } */
55
53
parent ;
56
54
55
+ #pending = false ;
56
+
57
57
/** @type {TemplateNode } */
58
58
#anchor;
59
59
@@ -81,6 +81,7 @@ export class Boundary {
81
81
/** @type {DocumentFragment | null } */
82
82
#offscreen_fragment = null ;
83
83
84
+ #local_pending_count = 0 ;
84
85
#pending_count = 0 ;
85
86
#is_creating_fallback = false ;
86
87
@@ -95,12 +96,12 @@ export class Boundary {
95
96
96
97
#effect_pending_update = ( ) => {
97
98
if ( this . #effect_pending) {
98
- internal_set ( this . #effect_pending, this . #pending_count ) ;
99
+ internal_set ( this . #effect_pending, this . #local_pending_count ) ;
99
100
}
100
101
} ;
101
102
102
103
#effect_pending_subscriber = createSubscriber ( ( ) => {
103
- this . #effect_pending = source ( this . #pending_count ) ;
104
+ this . #effect_pending = source ( this . #local_pending_count ) ;
104
105
105
106
if ( DEV ) {
106
107
tag ( this . #effect_pending, '$effect.pending()' ) ;
@@ -125,7 +126,7 @@ export class Boundary {
125
126
126
127
this . parent = /** @type {Effect } */ ( active_effect ) . b ;
127
128
128
- this . pending = ! ! this . #props. pending ;
129
+ this . # pending = ! ! this . #props. pending ;
129
130
130
131
this . #effect = block ( ( ) => {
131
132
/** @type {Effect } */ ( active_effect ) . b = this ;
@@ -156,7 +157,7 @@ export class Boundary {
156
157
this . #pending_effect = null ;
157
158
} ) ;
158
159
159
- this . pending = false ;
160
+ this . # pending = false ;
160
161
}
161
162
} ) ;
162
163
} else {
@@ -169,7 +170,7 @@ export class Boundary {
169
170
if ( this . #pending_count > 0 ) {
170
171
this . #show_pending_snippet( ) ;
171
172
} else {
172
- this . pending = false ;
173
+ this . # pending = false ;
173
174
}
174
175
}
175
176
} , flags ) ;
@@ -179,6 +180,14 @@ export class Boundary {
179
180
}
180
181
}
181
182
183
+ /**
184
+ * Returns `true` if the effect exists inside a boundary whose pending snippet is shown
185
+ * @returns {boolean }
186
+ */
187
+ is_pending ( ) {
188
+ return this . #pending || ( ! ! this . parent && this . parent . is_pending ( ) ) ;
189
+ }
190
+
182
191
has_pending_snippet ( ) {
183
192
return ! ! this . #props. pending ;
184
193
}
@@ -220,12 +229,25 @@ export class Boundary {
220
229
}
221
230
}
222
231
223
- /** @param {1 | -1 } d */
232
+ /**
233
+ * Updates the pending count associated with the currently visible pending snippet,
234
+ * if any, such that we can replace the snippet with content once work is done
235
+ * @param {1 | -1 } d
236
+ */
224
237
#update_pending_count( d ) {
238
+ if ( ! this . has_pending_snippet ( ) ) {
239
+ if ( this . parent ) {
240
+ this . parent . #update_pending_count( d ) ;
241
+ return ;
242
+ }
243
+
244
+ e . await_outside_boundary ( ) ;
245
+ }
246
+
225
247
this . #pending_count += d ;
226
248
227
249
if ( this . #pending_count === 0 ) {
228
- this . pending = false ;
250
+ this . # pending = false ;
229
251
230
252
if ( this . #pending_effect) {
231
253
pause_effect ( this . #pending_effect, ( ) => {
@@ -240,14 +262,16 @@ export class Boundary {
240
262
}
241
263
}
242
264
243
- /** @param {1 | -1 } d */
265
+ /**
266
+ * Update the source that powers `$effect.pending()` inside this boundary,
267
+ * and controls when the current `pending` snippet (if any) is removed.
268
+ * Do not call from inside the class
269
+ * @param {1 | -1 } d
270
+ */
244
271
update_pending_count ( d ) {
245
- if ( this . has_pending_snippet ( ) ) {
246
- this . #update_pending_count( d ) ;
247
- } else if ( this . parent ) {
248
- this . parent . #update_pending_count( d ) ;
249
- }
272
+ this . #update_pending_count( d ) ;
250
273
274
+ this . #local_pending_count += d ;
251
275
effect_pending_updates . add ( this . #effect_pending_update) ;
252
276
}
253
277
@@ -308,7 +332,7 @@ export class Boundary {
308
332
} ) ;
309
333
}
310
334
311
- this . pending = true ;
335
+ this . # pending = true ;
312
336
313
337
this . #main_effect = this . #run( ( ) => {
314
338
this . #is_creating_fallback = false ;
@@ -318,7 +342,7 @@ export class Boundary {
318
342
if ( this . #pending_count > 0 ) {
319
343
this . #show_pending_snippet( ) ;
320
344
} else {
321
- this . pending = false ;
345
+ this . # pending = false ;
322
346
}
323
347
} ;
324
348
@@ -384,12 +408,8 @@ function move_effect(effect, fragment) {
384
408
}
385
409
}
386
410
387
- export function get_pending_boundary ( ) {
388
- var boundary = /** @type {Effect } */ ( active_effect ) . b ;
389
-
390
- while ( boundary !== null && ! boundary . has_pending_snippet ( ) ) {
391
- boundary = boundary . parent ;
392
- }
411
+ export function get_boundary ( ) {
412
+ const boundary = /** @type {Effect } */ ( active_effect ) . b ;
393
413
394
414
if ( boundary === null ) {
395
415
e . await_outside_boundary ( ) ;
0 commit comments