Hasty Briefsbeta

Bilingual

Signals, the push-pull based algorithm

2 days ago
  • #Push-Pull Algorithm
  • #Signal
  • #Reactivity
  • Signals are a reactive programming concept that originated in the 1970s, with JavaScript implementations like Knockout.js and RxJS bringing reactive ideas to the browser.
  • Signals use a push-pull based algorithm: signals are push-based, eagerly notifying subscribers upon changes, while computeds are pull-based, lazily re-evaluating only when read after invalidation.
  • The auto-tracking dependency system in signals and computeds uses a global STACK to automatically establish links between sources and dependents without explicit dependency declarations.
  • A cache system with a dirty flag ensures computeds re-evaluate only when necessary, and dependencies are cleaned up and updated dynamically to maintain an accurate dependency graph.
  • This combination of push (invalidation) and pull (re-evaluation) enables fine-grained reactivity, adopted by frameworks like Solid, Vue, Preact, Angular, and Svelte, with potential future native standardization in JavaScript.