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

@ -1,8 +1,5 @@
/** @import { Effect, TemplateNode, Value } from '#client' */
/** @import { Batch } from '../../reactivity/batch.js' */
/** @import { TemplateNode, Value } from '#client' */
import { async_derived } from '../../reactivity/deriveds.js';
import { current_batch } from '../../reactivity/batch.js';
import { active_effect, schedule_effect } from '../../runtime.js';
import { capture, get_pending_boundary } from './boundary.js';
/**
@ -13,26 +10,15 @@ import { capture, get_pending_boundary } from './boundary.js';
export function async(node, expressions, fn) {
// TODO handle hydration
var batch = /** @type {Batch} */ (current_batch);
var effect = /** @type {Effect} */ (active_effect);
var boundary = get_pending_boundary(effect);
var ran = boundary.ran;
var restore = capture();
var boundary = get_pending_boundary();
boundary.increment();
Promise.all(expressions.map((fn) => async_derived(fn))).then((result) => {
if (ran) batch.restore();
restore();
fn(node, ...result);
// TODO is this necessary?
schedule_effect(effect);
if (ran) batch.flush();
boundary.decrement();
});
}

@ -327,9 +327,8 @@ function move_effect(effect, fragment) {
}
}
/** @param {Effect} effect */
export function get_pending_boundary(effect) {
let boundary = effect.b;
export function get_pending_boundary() {
var boundary = /** @type {Effect} */ (active_effect).b;
while (boundary !== null && !boundary.has_pending_snippet()) {
boundary = boundary.parent;
@ -367,7 +366,7 @@ export function capture(track = true) {
// TODO we should probably be incrementing the current batch, not the boundary?
export function suspend() {
let boundary = get_pending_boundary(/** @type {Effect} */ (active_effect));
let boundary = get_pending_boundary();
boundary.increment();

@ -104,7 +104,7 @@ export function async_derived(fn, location) {
throw new Error('TODO cannot create unowned async derived');
}
let boundary = get_pending_boundary(parent);
let boundary = get_pending_boundary();
var promise = /** @type {Promise<V>} */ (/** @type {unknown} */ (undefined));
var signal = source(/** @type {V} */ (UNINITIALIZED));

@ -346,7 +346,7 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
var batch = /** @type {Batch} */ (current_batch);
var restore = capture();
var boundary = get_pending_boundary(parent);
var boundary = get_pending_boundary();
var ran = boundary.ran;
Promise.all(async.map((expression) => async_derived(expression))).then((result) => {

Loading…
Cancel
Save