|
|
|
|
@ -36,7 +36,6 @@ import {
|
|
|
|
|
import { eager_effects, internal_set, set_eager_effects, source } from './sources.js';
|
|
|
|
|
import { get_error } from '../../shared/dev.js';
|
|
|
|
|
import { async_mode_flag, tracing_mode_flag } from '../../flags/index.js';
|
|
|
|
|
import { Boundary } from '../dom/blocks/boundary.js';
|
|
|
|
|
import { component_context } from '../context.js';
|
|
|
|
|
import { UNINITIALIZED } from '../../../constants.js';
|
|
|
|
|
import { batch_values, current_batch } from './batch.js';
|
|
|
|
|
@ -44,12 +43,16 @@ import { increment_pending, unset_context } from './async.js';
|
|
|
|
|
import { deferred, includes, noop } from '../../shared/utils.js';
|
|
|
|
|
import { set_signal_status, update_derived_status } from './status.js';
|
|
|
|
|
|
|
|
|
|
/** @type {Effect | null} */
|
|
|
|
|
export let current_async_effect = null;
|
|
|
|
|
/**
|
|
|
|
|
* This allows us to track 'reactivity loss' that occurs when signals
|
|
|
|
|
* are read after a non-context-restoring `await`. Dev-only
|
|
|
|
|
* @type {{ effect: Effect, warned: boolean } | null}
|
|
|
|
|
*/
|
|
|
|
|
export let reactivity_loss_tracker = null;
|
|
|
|
|
|
|
|
|
|
/** @param {Effect | null} v */
|
|
|
|
|
export function set_from_async_derived(v) {
|
|
|
|
|
current_async_effect = v;
|
|
|
|
|
/** @param {{ effect: Effect, warned: boolean } | null} v */
|
|
|
|
|
export function set_reactivity_loss_tracker(v) {
|
|
|
|
|
reactivity_loss_tracker = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const recent_async_deriveds = new Set();
|
|
|
|
|
@ -123,7 +126,12 @@ export function async_derived(fn, label, location) {
|
|
|
|
|
var deferreds = new Map();
|
|
|
|
|
|
|
|
|
|
async_effect(() => {
|
|
|
|
|
if (DEV) current_async_effect = active_effect;
|
|
|
|
|
if (DEV) {
|
|
|
|
|
reactivity_loss_tracker = {
|
|
|
|
|
effect: /** @type {Effect} */ (active_effect),
|
|
|
|
|
warned: false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @type {ReturnType<typeof deferred<V>>} */
|
|
|
|
|
var d = deferred();
|
|
|
|
|
@ -139,7 +147,9 @@ export function async_derived(fn, label, location) {
|
|
|
|
|
unset_context();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DEV) current_async_effect = null;
|
|
|
|
|
if (DEV) {
|
|
|
|
|
reactivity_loss_tracker = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var batch = /** @type {Batch} */ (current_batch);
|
|
|
|
|
|
|
|
|
|
@ -156,7 +166,9 @@ export function async_derived(fn, label, location) {
|
|
|
|
|
* @param {unknown} error
|
|
|
|
|
*/
|
|
|
|
|
const handler = (value, error = undefined) => {
|
|
|
|
|
current_async_effect = null;
|
|
|
|
|
if (DEV) {
|
|
|
|
|
reactivity_loss_tracker = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
batch.activate();
|
|
|
|
|
|
|
|
|
|
|