@@ -1386,15 +1386,7 @@ export function is_store(val) {
1386
1386
1387
1387
/**
1388
1388
* 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.
1398
1390
* @template V
1399
1391
* @param {Record<string, unknown> } props
1400
1392
* @param {string } key
@@ -1412,19 +1404,19 @@ export function prop(props, key, flags, initial) {
1412
1404
throw new Error ( 'Cannot use fallback values with bind:' ) ;
1413
1405
}
1414
1406
1415
- var value = /** @type {V } */ ( props [ key ] ) ;
1407
+ var prop_value = /** @type {V } */ ( props [ key ] ) ;
1416
1408
1417
- if ( value === undefined && initial !== undefined ) {
1409
+ if ( prop_value === undefined && initial !== undefined ) {
1418
1410
// @ts -expect-error would need a cumbersome method overload to type this
1419
1411
if ( ( flags & PROPS_IS_LAZY_INITIAL ) !== 0 ) initial = initial ( ) ;
1420
1412
1421
1413
if ( DEV && runes ) {
1422
1414
initial = readonly ( proxy ( /** @type {any } */ ( initial ) ) ) ;
1423
1415
}
1424
1416
1425
- value = /** @type {V } */ ( initial ) ;
1417
+ prop_value = /** @type {V } */ ( initial ) ;
1426
1418
1427
- if ( setter ) setter ( value ) ;
1419
+ if ( setter ) setter ( prop_value ) ;
1428
1420
}
1429
1421
1430
1422
var getter = ( ) => {
@@ -1453,15 +1445,16 @@ export function prop(props, key, flags, initial) {
1453
1445
1454
1446
// hard mode. this is where it gets ugly — the value in the child should
1455
1447
// 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.
1458
1449
var from_child = false ;
1459
1450
var was_from_child = false ;
1460
1451
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 ( ( ) => {
1463
1456
var parent_value = getter ( ) ;
1464
- var child_value = get ( s ) ;
1457
+ var child_value = get ( inner_current_value ) ;
1465
1458
1466
1459
if ( from_child ) {
1467
1460
from_child = false ;
@@ -1470,30 +1463,30 @@ export function prop(props, key, flags, initial) {
1470
1463
}
1471
1464
1472
1465
was_from_child = false ;
1473
- return ( s . v = parent_value ) ;
1466
+ return ( inner_current_value . v = parent_value ) ;
1474
1467
} ) ;
1475
1468
1476
- if ( ! immutable ) d . e = safe_equal ;
1469
+ if ( ! immutable ) current_value . e = safe_equal ;
1477
1470
1478
1471
return function ( /** @type {V } */ value , mutation = false ) {
1479
- var current = get ( d ) ;
1472
+ var current = get ( current_value ) ;
1480
1473
1481
1474
// legacy nonsense — need to ensure the source is invalidated when necessary
1482
1475
if ( is_signals_recorded ) {
1483
1476
// set this so that we don't reset to the parent value if `d`
1484
1477
// is invalidated because of `invalidate_inner_signals` (rather
1485
1478
// than because the parent or child value changed)
1486
1479
from_child = was_from_child ;
1487
-
1480
+ // invoke getters so that signals are picked up by `invalidate_inner_signals`
1488
1481
getter ( ) ;
1489
- get ( s ) ;
1482
+ get ( inner_current_value ) ;
1490
1483
}
1491
1484
1492
1485
if ( arguments . length > 0 ) {
1493
1486
if ( mutation || ( immutable ? value !== current : safe_not_equal ( value , current ) ) ) {
1494
1487
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
1497
1490
}
1498
1491
1499
1492
return value ;
0 commit comments