1
1
import { DEV } from 'esm-env' ;
2
2
import { subscribe_to_store } from '../../store/utils.js' ;
3
3
import { EMPTY_FUNC , run_all } from '../common.js' ;
4
- import { get_descriptors , is_array } from './utils.js' ;
4
+ import { get_descriptor , get_descriptors , is_array } from './utils.js' ;
5
+ import { PROPS_CALL_DEFAULT_VALUE , PROPS_IS_IMMUTABLE } from '../../constants.js' ;
5
6
6
7
export const SOURCE = 1 ;
7
8
export const DERIVED = 1 << 1 ;
@@ -30,8 +31,7 @@ let current_scheduler_mode = FLUSH_MICROTASK;
30
31
// Used for handling scheduling
31
32
let is_micro_task_queued = false ;
32
33
let is_task_queued = false ;
33
- // Used for exposing signals
34
- let is_signal_exposed = false ;
34
+
35
35
// Handle effect queues
36
36
37
37
/** @type {import('./types.js').EffectSignal[] } */
@@ -63,8 +63,6 @@ export let current_untracking = false;
63
63
/** Exists to opt out of the mutation validation for stores which may be set for the first time during a derivation */
64
64
let ignore_mutation_validation = false ;
65
65
66
- /** @type {null | import('./types.js').Signal } */
67
- let current_captured_signal = null ;
68
66
// If we are working with a get() chain that has no active container,
69
67
// to prevent memory leaks, we skip adding the consumer.
70
68
let current_skip_consumer = false ;
@@ -800,23 +798,6 @@ export function unsubscribe_on_destroy(stores) {
800
798
} ) ;
801
799
}
802
800
803
- /**
804
- * Wraps a function and marks execution context so that the last signal read from can be captured
805
- * using the `expose` function.
806
- * @template V
807
- * @param {() => V } fn
808
- * @returns {V }
809
- */
810
- export function exposable ( fn ) {
811
- const previous_is_signal_exposed = is_signal_exposed ;
812
- try {
813
- is_signal_exposed = true ;
814
- return fn ( ) ;
815
- } finally {
816
- is_signal_exposed = previous_is_signal_exposed ;
817
- }
818
- }
819
-
820
801
/**
821
802
* @template V
822
803
* @param {import('./types.js').Signal<V> } signal
@@ -836,10 +817,6 @@ export function get(signal) {
836
817
return signal . v ;
837
818
}
838
819
839
- if ( is_signal_exposed && current_should_capture_signal ) {
840
- current_captured_signal = signal ;
841
- }
842
-
843
820
if ( is_signals_recorded ) {
844
821
captured_signals . add ( signal ) ;
845
822
}
@@ -906,31 +883,6 @@ export function set_sync(signal, value) {
906
883
flushSync ( ( ) => set ( signal , value ) ) ;
907
884
}
908
885
909
- /**
910
- * Invokes a function and captures the last signal that is read during the invocation
911
- * if that signal is read within the `exposable` function context.
912
- * If a signal is captured, it returns the signal instead of the read value.
913
- * @template V
914
- * @param {() => V } possible_signal_fn
915
- * @returns {any }
916
- */
917
- export function expose ( possible_signal_fn ) {
918
- const previous_captured_signal = current_captured_signal ;
919
- const previous_should_capture_signal = current_should_capture_signal ;
920
- current_captured_signal = null ;
921
- current_should_capture_signal = true ;
922
- try {
923
- const value = possible_signal_fn ( ) ;
924
- if ( current_captured_signal === null ) {
925
- return value ;
926
- }
927
- return current_captured_signal ;
928
- } finally {
929
- current_captured_signal = previous_captured_signal ;
930
- current_should_capture_signal = previous_should_capture_signal ;
931
- }
932
- }
933
-
934
886
/**
935
887
* Invokes a function and captures all signals that are read during the invocation,
936
888
* then invalidates them.
@@ -1463,35 +1415,19 @@ export function is_store(val) {
1463
1415
* @template V
1464
1416
* @param {import('./types.js').MaybeSignal<Record<string, unknown>> } props_obj
1465
1417
* @param {string } key
1466
- * @param {boolean } immutable
1418
+ * @param {number } flags
1467
1419
* @param {V | (() => V) } [default_value]
1468
- * @param {boolean } [call_default_value]
1469
1420
* @returns {import('./types.js').Signal<V> | (() => V) }
1470
1421
*/
1471
- export function prop_source ( props_obj , key , immutable , default_value , call_default_value ) {
1422
+ export function prop_source ( props_obj , key , flags , default_value ) {
1423
+ const call_default_value = ( flags & PROPS_CALL_DEFAULT_VALUE ) !== 0 ;
1424
+ const immutable = ( flags & PROPS_IS_IMMUTABLE ) !== 0 ;
1425
+
1472
1426
const props = is_signal ( props_obj ) ? get ( props_obj ) : props_obj ;
1473
- const possible_signal = /** @type {import('./types.js').MaybeSignal<V> } */ (
1474
- expose ( ( ) => props [ key ] )
1475
- ) ;
1476
- const update_bound_prop = Object . getOwnPropertyDescriptor ( props , key ) ?. set ;
1427
+ const update_bound_prop = get_descriptor ( props , key ) ?. set ;
1477
1428
let value = props [ key ] ;
1478
1429
const should_set_default_value = value === undefined && default_value !== undefined ;
1479
1430
1480
- if (
1481
- is_signal ( possible_signal ) &&
1482
- possible_signal . v === value &&
1483
- update_bound_prop === undefined
1484
- ) {
1485
- if ( should_set_default_value ) {
1486
- set (
1487
- possible_signal ,
1488
- // @ts -expect-error would need a cumbersome method overload to type this
1489
- call_default_value ? default_value ( ) : default_value
1490
- ) ;
1491
- }
1492
- return possible_signal ;
1493
- }
1494
-
1495
1431
if ( should_set_default_value ) {
1496
1432
value =
1497
1433
// @ts -expect-error would need a cumbersome method overload to type this
@@ -1534,7 +1470,7 @@ export function prop_source(props_obj, key, immutable, default_value, call_defau
1534
1470
}
1535
1471
} ) ;
1536
1472
1537
- if ( is_signal ( possible_signal ) && update_bound_prop !== undefined ) {
1473
+ if ( update_bound_prop !== undefined ) {
1538
1474
let ignore_first = ! should_set_default_value ;
1539
1475
sync_effect ( ( ) => {
1540
1476
// Before if to ensure signal dependency is registered
@@ -1548,11 +1484,9 @@ export function prop_source(props_obj, key, immutable, default_value, call_defau
1548
1484
return ;
1549
1485
}
1550
1486
1551
- if ( not_equal ( immutable , propagating_value , possible_signal . v ) ) {
1552
- ignore_next1 = true ;
1553
- did_update_to_defined = true ;
1554
- untrack ( ( ) => update_bound_prop ( propagating_value ) ) ;
1555
- }
1487
+ ignore_next1 = true ;
1488
+ did_update_to_defined = true ;
1489
+ untrack ( ( ) => update_bound_prop ( propagating_value ) ) ;
1556
1490
} ) ;
1557
1491
}
1558
1492
0 commit comments