Build Angular signals: signal, computed and effect with versions, glitch-free reads, equal and untracked

hardAbout 60 minutesUpdated CodingProangularsignalsreactivitycomputedeffectsdependency-tracking
Not solved

Share this question

Problem

Angular signals are the base of modern Angular: templates, input(), computed() and effect() are all nodes in one reactive graph. Interviewers like to ask how that graph avoids extra work: why a computed is lazy, why it never shows a half-updated value (a "glitch"), and why a computed that recalculates to the same value does not wake up anything downstream. Build the core in plain JavaScript.

const price = signal(100);
const qty = signal(2);
const total = computed(() => price() * qty()); // nothing runs yet
effect(() => console.log("total", total()));
flushEffects();  // logs "total 200"
qty.set(3);
price.set(50);
flushEffects();  // logs "total 150" once, never "total 300"

Ref. UR-1450 · © UIRound · uiround.com/questions/build-angular-signals-signal-computed-and-effect-with-versions-glitch-free-reads-equal-and-untracked

Stuck? Take a hint

Try it in the editor

Run your code as often as you like. Submitting it to the full test suite is part of Pro.

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment