11import { DEV } from 'esm-env' ;
22import { subscribe_to_store } from '../../store/utils.js' ;
33import { 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' ;
56
67export const SOURCE = 1 ;
78export const DERIVED = 1 << 1 ;
@@ -30,8 +31,7 @@ let current_scheduler_mode = FLUSH_MICROTASK;
3031// Used for handling scheduling
3132let is_micro_task_queued = false ;
3233let is_task_queued = false ;
33- // Used for exposing signals
34- let is_signal_exposed = false ;
34+
3535// Handle effect queues
3636
3737/** @type {import('./types.js').EffectSignal[] } */
@@ -63,8 +63,6 @@ export let current_untracking = false;
6363/** Exists to opt out of the mutation validation for stores which may be set for the first time during a derivation */
6464let ignore_mutation_validation = false ;
6565
66- /** @type {null | import('./types.js').Signal } */
67- let current_captured_signal = null ;
6866// If we are working with a get() chain that has no active container,
6967// to prevent memory leaks, we skip adding the consumer.
7068let current_skip_consumer = false ;
@@ -800,23 +798,6 @@ export function unsubscribe_on_destroy(stores) {
800798 } ) ;
801799}
802800
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-
820801/**
821802 * @template V
822803 * @param {import('./types.js').Signal<V> } signal
@@ -836,10 +817,6 @@ export function get(signal) {
836817 return signal . v ;
837818 }
838819
839- if ( is_signal_exposed && current_should_capture_signal ) {
840- current_captured_signal = signal ;
841- }
842-
843820 if ( is_signals_recorded ) {
844821 captured_signals . add ( signal ) ;
845822 }
@@ -906,31 +883,6 @@ export function set_sync(signal, value) {
906883 flushSync ( ( ) => set ( signal , value ) ) ;
907884}
908885
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-
934886/**
935887 * Invokes a function and captures all signals that are read during the invocation,
936888 * then invalidates them.
@@ -1463,35 +1415,19 @@ export function is_store(val) {
14631415 * @template V
14641416 * @param {import('./types.js').MaybeSignal<Record<string, unknown>> } props_obj
14651417 * @param {string } key
1466- * @param {boolean } immutable
1418+ * @param {number } flags
14671419 * @param {V | (() => V) } [default_value]
1468- * @param {boolean } [call_default_value]
14691420 * @returns {import('./types.js').Signal<V> | (() => V) }
14701421 */
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+
14721426 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 ;
14771428 let value = props [ key ] ;
14781429 const should_set_default_value = value === undefined && default_value !== undefined ;
14791430
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-
14951431 if ( should_set_default_value ) {
14961432 value =
14971433 // @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
15341470 }
15351471 } ) ;
15361472
1537- if ( is_signal ( possible_signal ) && update_bound_prop !== undefined ) {
1473+ if ( update_bound_prop !== undefined ) {
15381474 let ignore_first = ! should_set_default_value ;
15391475 sync_effect ( ( ) => {
15401476 // Before if to ensure signal dependency is registered
@@ -1548,11 +1484,9 @@ export function prop_source(props_obj, key, immutable, default_value, call_defau
15481484 return ;
15491485 }
15501486
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 ) ) ;
15561490 } ) ;
15571491 }
15581492
0 commit comments