@@ -17,35 +17,35 @@ import { async_derived, derived, derived_safe_equal } from './deriveds.js';
1717export function flatten ( sync , async , fn ) {
1818 const d = is_runes ( ) ? derived : derived_safe_equal ;
1919
20- if ( async . length > 0 ) {
21- var batch = current_batch ;
22- var parent = /** @type {Effect } */ ( active_effect ) ;
20+ if ( async . length === 0 ) {
21+ fn ( sync . map ( d ) ) ;
22+ return ;
23+ }
2324
24- var restore = capture ( ) ;
25+ var batch = current_batch ;
26+ var parent = /** @type {Effect } */ ( active_effect ) ;
2527
26- var boundary = get_pending_boundary ( ) ;
28+ var restore = capture ( ) ;
29+ var boundary = get_pending_boundary ( ) ;
2730
28- Promise . all ( async . map ( ( expression ) => async_derived ( expression ) ) )
29- . then ( ( result ) => {
30- batch ?. activate ( ) ;
31+ Promise . all ( async . map ( ( expression ) => async_derived ( expression ) ) )
32+ . then ( ( result ) => {
33+ batch ?. activate ( ) ;
3134
32- restore ( ) ;
35+ restore ( ) ;
3336
34- try {
35- fn ( [ ...sync . map ( d ) , ...result ] ) ;
36- } catch ( error ) {
37- // ignore errors in blocks that have already been destroyed
38- if ( ( parent . f & DESTROYED ) === 0 ) {
39- invoke_error_boundary ( error , parent ) ;
40- }
37+ try {
38+ fn ( [ ...sync . map ( d ) , ...result ] ) ;
39+ } catch ( error ) {
40+ // ignore errors in blocks that have already been destroyed
41+ if ( ( parent . f & DESTROYED ) === 0 ) {
42+ invoke_error_boundary ( error , parent ) ;
4143 }
44+ }
4245
43- batch ?. deactivate ( ) ;
44- } )
45- . catch ( ( error ) => {
46- boundary . error ( error ) ;
47- } ) ;
48- } else {
49- fn ( sync . map ( d ) ) ;
50- }
46+ batch ?. deactivate ( ) ;
47+ } )
48+ . catch ( ( error ) => {
49+ boundary . error ( error ) ;
50+ } ) ;
5151}
0 commit comments