Skip to content

Commit 9844243

Browse files
authored
small readability tweaks
1 parent f0aa28f commit 9844243

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

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

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,15 +1386,7 @@ export function is_store(val) {
13861386

13871387
/**
13881388
* This function is responsible for synchronizing a possibly bound prop with the inner component state.
1389-
* It is used whenever the compiler sees that the component writes to the prop.
1390-
*
1391-
* - If the parent passes down a prop without binding, like `<Component prop={value} />`, then create a signal
1392-
* that updates whenever the value is updated from the parent or from within the component itself
1393-
* - If the parent passes down a prop with a binding, like `<Component bind:prop={value} />`, then
1394-
* - if the thing that is passed along is the original signal (not a property on it), and the equality functions
1395-
* are equal, then just use that signal, no need to create an intermediate one
1396-
* - otherwise create a signal that updates whenever the value is updated from the parent, and when it's updated
1397-
* from within the component itself, call the setter of the parent which will propagate the value change back
1389+
* It is used whenever the compiler sees that the component writes to the prop, or when it has a default prop_value.
13981390
* @template V
13991391
* @param {Record<string, unknown>} props
14001392
* @param {string} key
@@ -1412,19 +1404,19 @@ export function prop(props, key, flags, initial) {
14121404
throw new Error('Cannot use fallback values with bind:');
14131405
}
14141406

1415-
var value = /** @type {V} */ (props[key]);
1407+
var prop_value = /** @type {V} */ (props[key]);
14161408

1417-
if (value === undefined && initial !== undefined) {
1409+
if (prop_value === undefined && initial !== undefined) {
14181410
// @ts-expect-error would need a cumbersome method overload to type this
14191411
if ((flags & PROPS_IS_LAZY_INITIAL) !== 0) initial = initial();
14201412

14211413
if (DEV && runes) {
14221414
initial = readonly(proxy(/** @type {any} */ (initial)));
14231415
}
14241416

1425-
value = /** @type {V} */ (initial);
1417+
prop_value = /** @type {V} */ (initial);
14261418

1427-
if (setter) setter(value);
1419+
if (setter) setter(prop_value);
14281420
}
14291421

14301422
var getter = () => {
@@ -1453,15 +1445,16 @@ export function prop(props, key, flags, initial) {
14531445

14541446
// hard mode. this is where it gets ugly — the value in the child should
14551447
// synchronize with the parent, but it should also be possible to temporarily
1456-
// set the value to something else locally. to make this work, we need to
1457-
// do a little dance.
1448+
// set the value to something else locally.
14581449
var from_child = false;
14591450
var was_from_child = false;
14601451

1461-
var s = mutable_source(value);
1462-
var d = derived(() => {
1452+
// The derived returns the current value. The underlying mutable
1453+
// source is written to from various places to persist this value.
1454+
var inner_current_value = mutable_source(prop_value);
1455+
var current_value = derived(() => {
14631456
var parent_value = getter();
1464-
var child_value = get(s);
1457+
var child_value = get(inner_current_value);
14651458

14661459
if (from_child) {
14671460
from_child = false;
@@ -1470,30 +1463,30 @@ export function prop(props, key, flags, initial) {
14701463
}
14711464

14721465
was_from_child = false;
1473-
return (s.v = parent_value);
1466+
return (inner_current_value.v = parent_value);
14741467
});
14751468

1476-
if (!immutable) d.e = safe_equal;
1469+
if (!immutable) current_value.e = safe_equal;
14771470

14781471
return function (/** @type {V} */ value, mutation = false) {
1479-
var current = get(d);
1472+
var current = get(current_value);
14801473

14811474
// legacy nonsense — need to ensure the source is invalidated when necessary
14821475
if (is_signals_recorded) {
14831476
// set this so that we don't reset to the parent value if `d`
14841477
// is invalidated because of `invalidate_inner_signals` (rather
14851478
// than because the parent or child value changed)
14861479
from_child = was_from_child;
1487-
1480+
// invoke getters so that signals are picked up by `invalidate_inner_signals`
14881481
getter();
1489-
get(s);
1482+
get(inner_current_value);
14901483
}
14911484

14921485
if (arguments.length > 0) {
14931486
if (mutation || (immutable ? value !== current : safe_not_equal(value, current))) {
14941487
from_child = true;
1495-
set(s, mutation ? current : value);
1496-
get(d); // force a synchronisation immediately
1488+
set(inner_current_value, mutation ? current : value);
1489+
get(current_value); // force a synchronisation immediately
14971490
}
14981491

14991492
return value;

0 commit comments

Comments
 (0)