Welcome to the Angular Core Unidling documentation! 🌟 This guide explains how to use the unidling module in Angular to optimize application performance by managing idle states efficiently.

What is Unidling?

The unidling module is designed to detect and handle periods of user inactivity, allowing your Angular app to:

  • Pause background processes during idle times
  • Resume operations when user activity resumes
  • Reduce resource consumption without affecting user experience

💡 For deeper technical insights, check out our Angular Performance Optimization Guide!

How to Use

  1. Install the package

    npm install @angular/core-unidling
    
  2. Import in your component

    import { UnidlingService } from '@angular/core-unidling';
    
  3. Configure idle thresholds

    const unidling = new UnidlingService({
      idleTimeout: 60000, // 1 minute
      resumeTimeout: 30000 // 30 seconds
    });
    
  4. Attach to user activity events

    document.addEventListener('mousemove', unidling.resume);
    document.addEventListener('keydown', unidling.resume);
    

Common Use Cases

  • Background data fetching: Stop polling APIs when the user is idle.
  • UI animations: Pause animations to save CPU cycles.
  • Resource management: Free up memory or halt non-critical tasks.

Tips & Best Practices

  • 📌 Always pair unidling with user activity listeners for accurate state detection.
  • ⚠️ Avoid using it for critical operations that require real-time execution.
  • 🔄 Test with different timeout values to balance performance and usability.

Related Resources

angular_core_unidling