(signal)
| 525 | * @returns {V} |
| 526 | */ |
| 527 | export function get(signal) { |
| 528 | var flags = signal.f; |
| 529 | var is_derived = (flags & DERIVED) !== 0; |
| 530 | |
| 531 | captured_signals?.add(signal); |
| 532 | |
| 533 | // Register the dependency on the current reaction signal. |
| 534 | if (active_reaction !== null && !untracking) { |
| 535 | // if we're in a derived that is being read inside an _async_ derived, |
| 536 | // it's possible that the effect was already destroyed. In this case, |
| 537 | // we don't add the dependency, because that would create a memory leak |
| 538 | var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0; |
| 539 | |
| 540 | if (!destroyed && (current_sources === null || !current_sources.has(signal))) { |
| 541 | var deps = active_reaction.deps; |
| 542 | |
| 543 | if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) { |
| 544 | // we're in the effect init/update cycle |
| 545 | if (signal.rv < read_version) { |
| 546 | signal.rv = read_version; |
| 547 | |
| 548 | // If the signal is accessing the same dependencies in the same |
| 549 | // order as it did last time, increment `skipped_deps` |
| 550 | // rather than updating `new_deps`, which creates GC cost |
| 551 | if (new_deps === null && deps !== null && deps[skipped_deps] === signal) { |
| 552 | skipped_deps++; |
| 553 | } else if (new_deps === null) { |
| 554 | new_deps = [signal]; |
| 555 | } else { |
| 556 | new_deps.push(signal); |
| 557 | } |
| 558 | } |
| 559 | } else { |
| 560 | // We're adding a dependency outside the init/update cycle (i.e. after an `await`). |
| 561 | // We have to deduplicate deps/reactions in this case or remove_reactions could |
| 562 | // disconnect deps/reactions that are actually still in use (if skip_deps says |
| 563 | // "disconnect all after this index" and some of the signals are also present in |
| 564 | // list prior to the cutoff index, i.e. that should be kept). |
| 565 | active_reaction.deps ??= []; |
| 566 | if (!includes.call(active_reaction.deps, signal)) { |
| 567 | active_reaction.deps.push(signal); |
| 568 | } |
| 569 | |
| 570 | var reactions = signal.reactions; |
| 571 | |
| 572 | if (reactions === null) { |
| 573 | signal.reactions = [active_reaction]; |
| 574 | } else if (!includes.call(reactions, active_reaction)) { |
| 575 | reactions.push(active_reaction); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | if (DEV) { |
| 582 | if ( |
| 583 | !untracking && |
| 584 | reactivity_loss_tracker && |
no test coverage detected