improve waterfall detection

aa-coordination
Rich Harris 7 months ago
parent c56ee71653
commit 0a5628f456

@ -86,10 +86,11 @@ export function derived(fn) {
/** /**
* @template V * @template V
* @param {() => Promise<V>} fn * @param {() => Promise<V>} fn
* @param {boolean} detect_waterfall Whether to print a warning if the value is not read immediately after update
* @returns {Promise<Source<V>>} * @returns {Promise<Source<V>>}
*/ */
/*#__NO_SIDE_EFFECTS__*/ /*#__NO_SIDE_EFFECTS__*/
export function async_derived(fn) { export function async_derived(fn, detect_waterfall = true) {
let parent = /** @type {Effect | null} */ (active_effect); let parent = /** @type {Effect | null} */ (active_effect);
if (parent === null) { if (parent === null) {
@ -121,7 +122,7 @@ export function async_derived(fn) {
internal_set(value, v); internal_set(value, v);
if (DEV) { if (DEV && detect_waterfall) {
recent_async_deriveds.add(value); recent_async_deriveds.add(value);
setTimeout(() => { setTimeout(() => {

@ -358,7 +358,7 @@ export function template_effect(fn, sync = [], async = [], d = derived) {
var restore = capture(); var restore = capture();
var unsuspend = suspend(); var unsuspend = suspend();
Promise.all(async.map(async_derived)).then((result) => { Promise.all(async.map((expression) => async_derived(expression, false))).then((result) => {
restore(); restore();
if ((effect.f & DESTROYED) !== 0) { if ((effect.f & DESTROYED) !== 0) {

Loading…
Cancel
Save