blockless
Rich Harris 10 months ago
parent 8d383aed7e
commit 20b7b54b22

@ -16,11 +16,10 @@ export function derived(fn) {
/** @type {import('#client').Derived<V>} */
const signal = {
consumers: null,
d: null,
deps: null,
eq: default_equals,
f: flags,
fn: fn,
r: null,
// @ts-expect-error
v: UNINITIALIZED,
w: 0,
@ -33,10 +32,11 @@ export function derived(fn) {
}
if (current_consumer !== null) {
if (current_consumer.r === null) {
current_consumer.r = [signal];
const effect = /** @type {import('#client').Effect} */ (current_consumer);
if (effect.r === null) {
effect.r = [signal];
} else {
current_consumer.r.push(signal);
effect.r.push(signal);
}
}

@ -28,7 +28,7 @@ import {
function create_effect(type, fn, sync, schedule) {
/** @type {import('#client').Effect} */
const signal = {
d: null,
deps: null,
f: type | DIRTY,
l: 0,
fn: fn,

@ -29,11 +29,9 @@ export interface SourceDebug<V = unknown> extends Source<V> {
export interface Derived<V = unknown> extends Source<V> {
/** dependencies: Signals that this signal reads from */
d: null | ValueSignal[];
deps: null | ValueSignal[];
/** init: The function that we invoke for effects and computeds */
fn: () => V;
/** references: Anything that a signal owns */
r: null | Reaction[];
}
export interface DerivedDebug<V = unknown> extends Derived<V> {
@ -44,7 +42,7 @@ export interface Effect {
/** context: The associated component if this signal is an effect/computed */
ctx: null | ComponentContext;
/** dependencies: Signals that this signal reads from */
d: null | ValueSignal[];
deps: null | ValueSignal[];
/** destroy: Thing(s) that need destroying */
y: null | (() => void);
/** The types that the signal represent, as a bitwise value */

@ -163,7 +163,7 @@ function is_signal_dirty(signal) {
}
if ((flags & MAYBE_DIRTY) !== 0) {
const dependencies = /** @type {import('#client').Reaction} **/ (signal).d;
const dependencies = /** @type {import('#client').Reaction} **/ (signal).deps;
if (dependencies !== null) {
const length = dependencies.length;
@ -230,7 +230,7 @@ function execute_reaction(signal) {
try {
const res = /** @type {() => V} */ (init)();
let dependencies = /** @type {import('#client').ValueSignal<unknown>[]} **/ (signal.d);
let dependencies = /** @type {import('#client').ValueSignal<unknown>[]} **/ (signal.deps);
if (current_dependencies !== null) {
let i;
if (dependencies !== null) {
@ -265,7 +265,7 @@ function execute_reaction(signal) {
dependencies[current_dependencies_index + i] = current_dependencies[i];
}
} else {
signal.d = /** @type {import('#client').ValueSignal<V>[]} **/ (
signal.deps = /** @type {import('#client').ValueSignal<V>[]} **/ (
dependencies = current_dependencies
);
}
@ -336,7 +336,7 @@ function remove_consumer(signal, dependency) {
* @returns {void}
*/
function remove_consumers(signal, start_index) {
const dependencies = signal.d;
const dependencies = signal.deps;
if (dependencies !== null) {
const active_dependencies = start_index === 0 ? null : dependencies.slice(0, start_index);
let i;
@ -664,7 +664,7 @@ function update_derived(signal, force_schedule) {
updating_derived = previous_updating_derived;
const status =
(current_skip_consumer || (signal.f & UNOWNED) !== 0) && signal.d !== null
(current_skip_consumer || (signal.f & UNOWNED) !== 0) && signal.deps !== null
? MAYBE_DIRTY
: CLEAN;
@ -706,7 +706,7 @@ export function get(signal) {
// Register the dependency on the current consumer signal.
if (current_consumer !== null && (current_consumer.f & MANAGED) === 0 && !current_untracking) {
const unowned = (current_consumer.f & UNOWNED) !== 0;
const dependencies = current_consumer.d;
const dependencies = current_consumer.deps;
if (
current_dependencies === null &&
dependencies !== null &&

@ -229,7 +229,7 @@ describe('signals', () => {
// Ensure we're not leaking dependencies
assert.deepEqual(
nested.slice(0, -2).map((s) => s.d),
nested.slice(0, -2).map((s) => s.deps),
[null, null]
);
};

Loading…
Cancel
Save