pull/16197/head
Rich Harris 5 months ago
parent d7f580d2cb
commit 399bda5d7c

@ -26,7 +26,7 @@ export function AwaitExpression(node, context) {
// @ts-expect-error we could probably use a neater/more robust mechanism // @ts-expect-error we could probably use a neater/more robust mechanism
if (parent.metadata) break; if (parent.metadata) break;
// TODO make this more accurate — we don't need to call suspend // TODO make this more accurate — we don't need to call suspend
// if this is the last thing that could be read // if this is the last thing that could be read
preserve_context = true; preserve_context = true;
} }

@ -283,7 +283,7 @@ export function each(node, flags, get_collection, get_key, render_fn, fallback_f
update_item(existing, value, i, flags); update_item(existing, value, i, flags);
} }
} else { } else {
var item = create_item( item = create_item(
null, null,
state, state,
null, null,

@ -130,14 +130,17 @@ export class Batch {
batches.delete(this); batches.delete(this);
for (var batch of batches) { for (var batch of batches) {
/** @type {Source} */
var source;
if (batch.#id < this.#id) { if (batch.#id < this.#id) {
// other batch is older than this // other batch is older than this
for (var source of this.#previous.keys()) { for (source of this.#previous.keys()) {
batch.#previous.delete(source); batch.#previous.delete(source);
} }
} else { } else {
// other batch is newer than this // other batch is newer than this
for (var source of batch.#previous.keys()) { for (source of batch.#previous.keys()) {
if (this.#previous.has(source)) { if (this.#previous.has(source)) {
batch.#previous.set(source, source.v); batch.#previous.set(source, source.v);
} }

@ -89,7 +89,7 @@ export function derived(fn) {
/** /**
* @template V * @template V
* @param {() => Promise<V>} fn * @param {() => V | Promise<V>} fn
* @param {string} [location] If provided, print a warning if the value is not read immediately after update * @param {string} [location] If provided, print a warning if the value is not read immediately after update
* @returns {Promise<Source<V>>} * @returns {Promise<Source<V>>}
*/ */
@ -173,12 +173,21 @@ export function async_derived(fn, location) {
); );
}, EFFECT_ASYNC | EFFECT_PRESERVED); }, EFFECT_ASYNC | EFFECT_PRESERVED);
return new Promise(async (fulfil) => { return new Promise((fulfil) => {
/** @param {Promise<V>} p */
function next(p) {
p.then(() => {
if (p === promise) {
fulfil(signal);
} else {
// if the effect re-runs before the initial promise // if the effect re-runs before the initial promise
// resolves, delay resolution until we have a value // resolves, delay resolution until we have a value
var p; next(promise);
while (p !== (p = promise)) await p; }
fulfil(signal); });
}
next(promise);
}); });
} }

Loading…
Cancel
Save