reduce indirection

blockless
Rich Harris 11 months ago
parent b81a1fb7a2
commit 393c2d5090

@ -20,23 +20,39 @@ import {
} from '../constants.js';
/**
* @template V
* @param {import('./types.js').SignalFlags} flags
* @param {V} value
* @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 create_computation_signal(flags, value) {
function internal_create_effect(type, fn, sync, schedule) {
/** @type {import('#client').Effect} */
const signal = {
c: null,
d: null,
e: null,
f: flags,
f: type | DIRTY,
l: 0,
i: null,
i: fn,
r: null,
v: value,
v: null,
w: 0,
x: null,
x: current_component_context,
y: null,
in: null,
out: null,
@ -50,41 +66,15 @@ function create_computation_signal(flags, value) {
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) {
signal.l = current_effect.l + 1;
push_reference(current_effect, signal);
}
if (schedule) {
schedule_effect(signal, sync);
}
return signal;
}

Loading…
Cancel
Save