Angular πŸ‡ΊπŸ‡¦ - practical notes
1.63K subscribers
1.6K photos
1 file
532 links
Angular - practical notes

This group is for posting practical notes for Angular developers. Mostly all posts are for quick implementation https://t.me/angular_practical_notes (Commenting on posts only in ENG and UA langs here). Welcome!
Download Telegram
πŸ“΅ Optimizing JavaScript’s Event Loop

#settimeout #setinterval #event_loop #requestAnimationFrame

Why setTimeout is Inaccurate? ❌

setTimeout and setInterval in JavaScript are based on the event loop and task queue. Their execution time may vary due to several factors:

Event Loop Mechanism:

JavaScript executes code within a single event loop. If earlier tasks take a long time or the task queue is busy, the timer callback will be delayed.

Task Queue Priority:

The priority of tasks in the task queue varies. User interaction events or rendering updates might have higher priority than setTimeout and setInterval, delaying their execution.

JavaScript Engine Limitations:

The JS engine normally imposes a minimum delay; for example, nested setTimeout calls usually have a minimum delay of 4 milliseconds.

System Performance and Load:

System performance and current load can also affect timer accuracy. High system load can further delay task execution.


βœ…
Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
❀️ Stop Using setTimeout in Angular

#angular #setTimeout

What setTimeout Really Does in Angular
In JavaScript, setTimeout queues a task on the macrotask queue to be run after the current call stack clears. In a normal JS app, this is predictable.

But Angular isn’t just JavaScript β€” it uses Zone.js under the hood.

Zone.js monkey-patches setTimeout so Angular can trigger change detection after async operations.

Every time setTimeout fires, Angular knows something changed. So it runs its entire component tree check cycle.


βœ… Article Link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
2πŸ‘4❀1