merge async

async-changeset
Rich Harris 7 months ago
commit 30267cf35b

@ -23,6 +23,7 @@ export const EFFECT_PRESERVED = 1 << 21; // effects with this flag should not be
// Flags used for async // Flags used for async
export const REACTION_IS_UPDATING = 1 << 22; export const REACTION_IS_UPDATING = 1 << 22;
export const EFFECT_ASYNC = 1 << 23;
export const STATE_SYMBOL = Symbol('$state'); export const STATE_SYMBOL = Symbol('$state');
export const STATE_SYMBOL_METADATA = Symbol('$state metadata'); export const STATE_SYMBOL_METADATA = Symbol('$state metadata');

@ -7,6 +7,7 @@ import {
CLEAN, CLEAN,
DERIVED, DERIVED,
EFFECT, EFFECT,
EFFECT_ASYNC,
MAYBE_DIRTY, MAYBE_DIRTY,
RENDER_EFFECT, RENDER_EFFECT,
ROOT_EFFECT ROOT_EFFECT
@ -39,6 +40,8 @@ export function log_effect_tree(effect) {
label = 'boundary'; label = 'boundary';
} else if ((flags & BLOCK_EFFECT) !== 0) { } else if ((flags & BLOCK_EFFECT) !== 0) {
label = 'block'; label = 'block';
} else if ((flags & EFFECT_ASYNC) !== 0) {
label = 'async';
} else if ((flags & BRANCH_EFFECT) !== 0) { } else if ((flags & BRANCH_EFFECT) !== 0) {
label = 'branch'; label = 'branch';
} else if ((flags & RENDER_EFFECT) !== 0) { } else if ((flags & RENDER_EFFECT) !== 0) {

@ -5,6 +5,7 @@ import {
DERIVED, DERIVED,
DESTROYED, DESTROYED,
DIRTY, DIRTY,
EFFECT_ASYNC,
EFFECT_PRESERVED, EFFECT_PRESERVED,
MAYBE_DIRTY, MAYBE_DIRTY,
UNOWNED UNOWNED
@ -22,7 +23,7 @@ import {
import { equals, safe_equals } from './equality.js'; import { equals, safe_equals } from './equality.js';
import * as e from '../errors.js'; import * as e from '../errors.js';
import * as w from '../warnings.js'; import * as w from '../warnings.js';
import { block, destroy_effect } from './effects.js'; import { block, destroy_effect, render_effect } from './effects.js';
import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js'; import { inspect_effects, internal_set, set_inspect_effects, source } from './sources.js';
import { get_stack } from '../dev/tracing.js'; import { get_stack } from '../dev/tracing.js';
import { tracing_mode_flag } from '../../flags/index.js'; import { tracing_mode_flag } from '../../flags/index.js';
@ -110,8 +111,7 @@ export function async_derived(fn, location) {
/** @type {(() => void) | null} */ /** @type {(() => void) | null} */
var discard = null; var discard = null;
// TODO this isn't a block render_effect(() => {
block(() => {
if (DEV) from_async_derived = active_effect; if (DEV) from_async_derived = active_effect;
var current = (promise = fn()); var current = (promise = fn());
if (DEV) from_async_derived = null; if (DEV) from_async_derived = null;
@ -165,7 +165,7 @@ export function async_derived(fn, location) {
} }
} }
); );
}, EFFECT_PRESERVED); }, EFFECT_ASYNC | EFFECT_PRESERVED);
return new Promise(async (fulfil) => { return new Promise(async (fulfil) => {
// if the effect re-runs before the initial promise // if the effect re-runs before the initial promise

@ -335,8 +335,8 @@ export function legacy_pre_effect_reset() {
* @param {() => void | (() => void)} fn * @param {() => void | (() => void)} fn
* @returns {Effect} * @returns {Effect}
*/ */
export function render_effect(fn) { export function render_effect(fn, flags = 0) {
return create_effect(RENDER_EFFECT, fn, true); return create_effect(RENDER_EFFECT | flags, fn, true);
} }
/** /**

@ -28,7 +28,8 @@ import {
UNOWNED, UNOWNED,
MAYBE_DIRTY, MAYBE_DIRTY,
BLOCK_EFFECT, BLOCK_EFFECT,
ROOT_EFFECT ROOT_EFFECT,
EFFECT_ASYNC
} from '../constants.js'; } from '../constants.js';
import * as e from '../errors.js'; import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js'; import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
@ -154,7 +155,7 @@ export function set(source, value) {
active_reaction !== null && active_reaction !== null &&
!untracking && !untracking &&
is_runes() && is_runes() &&
(active_reaction.f & (DERIVED | BLOCK_EFFECT)) !== 0 && (active_reaction.f & (DERIVED | BLOCK_EFFECT | EFFECT_ASYNC)) !== 0 &&
// If the source was created locally within the current derived, then // If the source was created locally within the current derived, then
// we allow the mutation. // we allow the mutation.
(derived_sources === null || !derived_sources.includes(source)) (derived_sources === null || !derived_sources.includes(source))

@ -23,7 +23,8 @@ import {
LEGACY_DERIVED_PROP, LEGACY_DERIVED_PROP,
DISCONNECTED, DISCONNECTED,
BOUNDARY_EFFECT, BOUNDARY_EFFECT,
REACTION_IS_UPDATING REACTION_IS_UPDATING,
EFFECT_ASYNC
} from './constants.js'; } from './constants.js';
import { import {
flush_idle_tasks, flush_idle_tasks,
@ -821,7 +822,7 @@ function process_effects(effect, fork) {
var sibling = current_effect.next; var sibling = current_effect.next;
if (!is_skippable_branch && (flags & INERT) === 0) { if (!is_skippable_branch && (flags & INERT) === 0) {
if (fork !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT)) === 0) { if (fork !== undefined && (flags & (BLOCK_EFFECT | BRANCH_EFFECT | EFFECT_ASYNC)) === 0) {
if ((current_effect.f & CLEAN) === 0) { if ((current_effect.f & CLEAN) === 0) {
// Inside a boundary, defer everything except block/branch effects // Inside a boundary, defer everything except block/branch effects
fork.add_effect(current_effect); fork.add_effect(current_effect);

Loading…
Cancel
Save