pull/16197/head
Rich Harris 4 months ago
parent c8e47cc98d
commit 7f0072bfaa

@ -1,5 +1,7 @@
/** @import { TemplateNode, Value } from '#client' */
/** @import { Effect, TemplateNode, Value } from '#client' */
import { DESTROYED } from '#client/constants';
import { async_derived } from '../../reactivity/deriveds.js';
import { active_effect } from '../../runtime.js';
import { capture, get_pending_boundary } from './boundary.js';
/**
@ -10,12 +12,16 @@ import { capture, get_pending_boundary } from './boundary.js';
export function async(node, expressions, fn) {
// TODO handle hydration
var parent = /** @type {Effect} */ (active_effect);
var restore = capture();
var boundary = get_pending_boundary();
boundary.increment();
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
if ((parent.f & DESTROYED) !== 0) return;
restore();
fn(node, ...result);

@ -34,15 +34,14 @@ import {
EFFECT_PRESERVED,
STALE_REACTION
} from '#client/constants';
import { set } from './sources.js';
import * as e from '../errors.js';
import { DEV } from 'esm-env';
import { define_property } from '../../shared/utils.js';
import { get_next_sibling } from '../dom/operations.js';
import { async_derived, derived } from './deriveds.js';
import { capture, get_pending_boundary } from '../dom/blocks/boundary.js';
import { capture } from '../dom/blocks/boundary.js';
import { component_context, dev_current_component_function } from '../context.js';
import { current_batch, Batch } from './batch.js';
import { Batch } from './batch.js';
/**
* @param {'$effect' | '$effect.pre' | '$inspect'} rune
@ -343,24 +342,13 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
var parent = /** @type {Effect} */ (active_effect);
if (async.length > 0) {
var batch = /** @type {Batch} */ (current_batch);
var restore = capture();
var boundary = get_pending_boundary();
var ran = boundary.ran;
Promise.all(async.map((expression) => async_derived(expression))).then((result) => {
restore();
if ((parent.f & DESTROYED) !== 0) {
return;
}
var effect = create_template_effect(fn, [...sync.map(d), ...result]);
if ((parent.f & DESTROYED) !== 0) return;
if (ran) batch.restore();
schedule_effect(effect);
if (ran) batch.flush();
restore();
create_template_effect(fn, [...sync.map(d), ...result]);
});
} else {
create_template_effect(fn, sync.map(d));
@ -380,7 +368,7 @@ function create_template_effect(fn, deriveds) {
});
}
return create_effect(RENDER_EFFECT, effect, true);
create_effect(RENDER_EFFECT, effect, true);
}
/**

Loading…
Cancel
Save