reduce indirection

blockless
Rich Harris 11 months ago
parent b81a1fb7a2
commit 393c2d5090

@ -20,23 +20,39 @@ import {
} from '../constants.js'; } from '../constants.js';
/** /**
* @template V * @param {import('#client').Reaction} target_signal
* @param {import('./types.js').SignalFlags} flags * @param {import('#client').Reaction} ref_signal
* @param {V} value * @returns {void}
*/
export function push_reference(target_signal, ref_signal) {
const references = target_signal.r;
if (references === null) {
target_signal.r = [ref_signal];
} else {
references.push(ref_signal);
}
}
/**
* @param {import('./types.js').EffectType} type
* @param {(() => void | (() => void))} fn
* @param {boolean} sync
* @param {boolean} schedule
* @returns {import('#client').Effect}
*/ */
function create_computation_signal(flags, value) { function internal_create_effect(type, fn, sync, schedule) {
/** @type {import('#client').Effect} */ /** @type {import('#client').Effect} */
const signal = { const signal = {
c: null, c: null,
d: null, d: null,
e: null, e: null,
f: flags, f: type | DIRTY,
l: 0, l: 0,
i: null, i: fn,
r: null, r: null,
v: value, v: null,
w: 0, w: 0,
x: null, x: current_component_context,
y: null, y: null,
in: null, in: null,
out: null, out: null,
@ -50,41 +66,15 @@ function create_computation_signal(flags, value) {
signal.inspect = new Set(); signal.inspect = new Set();
} }
return signal;
}
/**
* @param {import('#client').Reaction} target_signal
* @param {import('#client').Reaction} ref_signal
* @returns {void}
*/
export function push_reference(target_signal, ref_signal) {
const references = target_signal.r;
if (references === null) {
target_signal.r = [ref_signal];
} else {
references.push(ref_signal);
}
}
/**
* @param {import('./types.js').EffectType} type
* @param {(() => void | (() => void))} fn
* @param {boolean} sync
* @param {boolean} schedule
* @returns {import('#client').Effect}
*/
function internal_create_effect(type, fn, sync, schedule) {
const signal = create_computation_signal(type | DIRTY, null);
signal.i = fn;
signal.x = current_component_context;
if (current_effect !== null) { if (current_effect !== null) {
signal.l = current_effect.l + 1; signal.l = current_effect.l + 1;
push_reference(current_effect, signal); push_reference(current_effect, signal);
} }
if (schedule) { if (schedule) {
schedule_effect(signal, sync); schedule_effect(signal, sync);
} }
return signal; return signal;
} }

Loading…
Cancel
Save