Skip to content

Commit a544f25

Browse files
committed
wip
1 parent 796a226 commit a544f25

File tree

3 files changed

+61
-38
lines changed

3 files changed

+61
-38
lines changed

packages/svelte/src/internal/client/dom/blocks/boundary.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ export function boundary(node, props, children) {
164164
}
165165

166166
// @ts-ignore
167-
var sources = boundary.fn.sources;
168-
for (var [source, entry] of sources) {
169-
if (source.v !== entry.v) {
170-
mark_reactions(source, DIRTY, source);
167+
var forks = boundary.fn.forks;
168+
for (var [signal, entry] of forks) {
169+
if (signal.v !== entry.v) {
170+
mark_reactions(signal, DIRTY);
171171
}
172172
}
173-
sources.clear();
173+
forks.clear();
174174

175175
for (const fn of callbacks) fn();
176176
callbacks.clear();
@@ -314,7 +314,7 @@ export function boundary(node, props, children) {
314314
};
315315

316316
// @ts-ignore
317-
boundary.fn.sources = new Map();
317+
boundary.fn.forks = new Map();
318318

319319
// @ts-ignore
320320
boundary.fn.is_pending = () => props.pending;

packages/svelte/src/internal/client/reactivity/sources.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export function set(source, value) {
170170
export function internal_set(source, value) {
171171
if (!source.equals(value)) {
172172

173-
mark_reactions(source, DIRTY, source);
173+
mark_reactions(source, DIRTY);
174174

175175
var old_value = source.v;
176176
source.v = value;
@@ -258,10 +258,9 @@ export function update_pre(source, d = 1) {
258258
/**
259259
* @param {Value} signal
260260
* @param {number} status should be DIRTY or MAYBE_DIRTY
261-
* @param {Source} [source]
262261
* @returns {void}
263262
*/
264-
export function mark_reactions(signal, status, source) {
263+
export function mark_reactions(signal, status) {
265264
var reactions = signal.reactions;
266265
if (reactions === null) return;
267266

@@ -289,9 +288,9 @@ export function mark_reactions(signal, status, source) {
289288
// If the signal a) was previously clean or b) is an unowned derived, then mark it
290289
if ((flags & (CLEAN | UNOWNED)) !== 0) {
291290
if ((flags & DERIVED) !== 0) {
292-
mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY, source);
291+
mark_reactions(/** @type {Derived} */ (reaction), MAYBE_DIRTY);
293292
} else {
294-
schedule_effect(/** @type {Effect} */ (reaction), source);
293+
schedule_effect(/** @type {Effect} */ (reaction));
295294
}
296295
}
297296
}

packages/svelte/src/internal/client/runtime.js

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
update_derived
4141
} from './reactivity/deriveds.js';
4242
import * as e from './errors.js';
43-
import { FILENAME } from '../../constants.js';
43+
import { FILENAME, UNINITIALIZED } from '../../constants.js';
4444
import { tracing_mode_flag } from '../flags/index.js';
4545
import { tracing_expressions, get_stack } from './dev/tracing.js';
4646
import {
@@ -783,24 +783,44 @@ function flush_deferred() {
783783
}
784784
}
785785

786+
/**
787+
* @param {Source | Derived} signal
788+
* @param {any} forks
789+
*/
790+
function fork_dependencies(signal, forks) {
791+
var entry = forks.get(signal);
792+
if (entry === undefined) {
793+
entry = { v: signal.v };
794+
forks.set(signal, entry);
795+
if ((signal.f & DERIVED) !== 0) {
796+
var deps = /** @type {Derived} */ (signal).deps;
797+
if (deps !== null) {
798+
for (var i = 0; i < deps.length; i++) {
799+
fork_dependencies(deps[i], forks);
800+
}
801+
}
802+
}
803+
}
804+
}
805+
786806
/**
787807
* @param {Effect} signal
788-
* @param {Source} [source]
789808
* @returns {void}
790809
*/
791-
export function schedule_effect(signal, source) {
792-
if (source && (signal.f & ASYNC_DERIVED) !== 0) {
810+
export function schedule_effect(signal) {
811+
if ((signal.f & ASYNC_DERIVED) !== 0) {
793812
if (active_effect === signal) {
794813
set_signal_status(signal, MAYBE_DIRTY);
795814
return;
796815
}
797816
var boundary = get_boundary(signal);
798817
// @ts-ignore
799-
var sources = boundary.fn.sources;
800-
var entry = sources.get(source);
801-
if (entry === undefined) {
802-
entry = { v: source.v };
803-
sources.set(source, entry);
818+
var forks = boundary.fn.forks;
819+
var deps = signal.deps;
820+
if (deps !== null) {
821+
for (var i = 0; i < deps.length; i++) {
822+
fork_dependencies(deps[i], forks);
823+
}
804824
}
805825
}
806826

@@ -1043,28 +1063,32 @@ export function get(signal) {
10431063
}
10441064
}
10451065

1046-
var value = signal.v;
1066+
var value = /** @type {V} */ (UNINITIALIZED);
10471067

1048-
if (is_derived) {
1049-
derived = /** @type {Derived} */ (signal);
1068+
var target_effect = event_boundary_effect ?? active_effect;
10501069

1051-
if (check_dirtiness(derived)) {
1052-
update_derived(derived);
1070+
if (target_effect !== null && !is_flushing_async_derived) {
1071+
var boundary = get_boundary(target_effect);
1072+
if (boundary !== null) {
1073+
// @ts-ignore
1074+
var forks = boundary.fn.forks;
1075+
var entry = forks.get(signal);
1076+
if (entry !== undefined) {
1077+
value = entry.v;
1078+
}
10531079
}
1054-
value = signal.v;
1055-
} else {
1056-
var target_effect = event_boundary_effect ?? active_effect;
1057-
1058-
if (target_effect !== null && !is_flushing_async_derived) {
1059-
var boundary = get_boundary(target_effect);
1060-
if (boundary !== null) {
1061-
// @ts-ignore
1062-
var sources = boundary.fn.sources;
1063-
var entry = sources.get(signal);
1064-
if (entry !== undefined) {
1065-
value = entry.v;
1066-
}
1080+
}
1081+
1082+
if (value === UNINITIALIZED) {
1083+
if (is_derived) {
1084+
derived = /** @type {Derived} */ (signal);
1085+
1086+
if (check_dirtiness(derived)) {
1087+
update_derived(derived);
10671088
}
1089+
value = signal.v;
1090+
} else {
1091+
value = signal.v;
10681092
}
10691093
}
10701094

0 commit comments

Comments
 (0)