async-fork
Dominic Gannaway 7 months ago
parent 694cbbb1f3
commit 054f8261a9

@ -28,7 +28,7 @@ import { block, destroy_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';
import { capture, suspend } from '../dom/blocks/boundary.js'; import { capture, get_boundary, suspend } from '../dom/blocks/boundary.js';
import { component_context } from '../context.js'; import { component_context } from '../context.js';
import { UNINITIALIZED } from '../../../constants.js'; import { UNINITIALIZED } from '../../../constants.js';
@ -127,6 +127,16 @@ export function async_derived(fn, location) {
restore(); restore();
from_async_derived = null; from_async_derived = null;
if (signal.v !== UNINITIALIZED) {
var boundary = get_boundary(parent);
// @ts-ignore
var forks = boundary.fn.forks;
var entry = forks.get(signal);
if (entry === undefined) {
entry = { v: signal.v };
forks.set(signal, entry);
}
}
internal_set(signal, v); internal_set(signal, v);
if (DEV && location !== undefined) { if (DEV && location !== undefined) {

@ -171,7 +171,7 @@ export function set(source, value) {
*/ */
export function internal_set(source, value) { export function internal_set(source, value) {
if (!source.equals(value)) { if (!source.equals(value)) {
possibly_fork(source); possibly_fork_reactions(source);
var old_value = source.v; var old_value = source.v;
source.v = value; source.v = value;
@ -342,7 +342,7 @@ function fork_dependencies(signal, forks) {
* @param {Value} signal * @param {Value} signal
* @returns {void} * @returns {void}
*/ */
function possibly_fork(signal) { function possibly_fork_reactions(signal) {
var reactions = signal.reactions; var reactions = signal.reactions;
if (reactions === null) return; if (reactions === null) return;
@ -362,7 +362,7 @@ function possibly_fork(signal) {
// If the signal a) was previously clean or b) is an unowned derived, then mark it // If the signal a) was previously clean or b) is an unowned derived, then mark it
if ((flags & (CLEAN | UNOWNED)) !== 0) { if ((flags & (CLEAN | UNOWNED)) !== 0) {
if ((flags & DERIVED) !== 0) { if ((flags & DERIVED) !== 0) {
possibly_fork(/** @type {Derived} */ (reaction)); possibly_fork_reactions(/** @type {Derived} */ (reaction));
} else { } else {
if ((reaction.f & ASYNC_DERIVED) !== 0) { if ((reaction.f & ASYNC_DERIVED) !== 0) {
// if (active_effect === signal) { // if (active_effect === signal) {

Loading…
Cancel
Save