Skip to content

Comments

feat(useIdle): implement Stoppable interface#5068

Merged
antfu merged 11 commits intovueuse:mainfrom
dpbs-715:main
Oct 22, 2025
Merged

feat(useIdle): implement Stoppable interface#5068
antfu merged 11 commits intovueuse:mainfrom
dpbs-715:main

Conversation

@dpbs-715
Copy link
Contributor

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

Added stop and reuse methods to the useIdle composable function:

  • stop method: Cleans up all active event listeners and clears the idle detection timer, allowing for proper resource cleanup when the composable is no longer needed
  • reuse method: Re-initializes the idle detection functionality by re-attaching all event listeners, providing a way to restart the composable after it has been stopped

These methods provide better lifecycle management for the useIdle composable, following VueUse's standard patterns for composable functions that need cleanup and re-initialization capabilities.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 25, 2025
@dpbs-715 dpbs-715 closed this Sep 25, 2025
@dpbs-715 dpbs-715 reopened this Sep 25, 2025
@9romise
Copy link
Member

9romise commented Sep 25, 2025

Could you briefly describe the use case for this change?

@dpbs-715
Copy link
Contributor Author

dpbs-715 commented Sep 25, 2025

For example, useIdle is used globally in the system to monitor user operations and display the leave status. If you want to pause these monitoring in some routes (such as the page for watching videos), it is more convenient to add these two methods

const { idle,stop,reuse } = useIdle(5000)

@OrbisK OrbisK changed the title feat(useIdle):add stop and reuse methods for useIdle composable feat(useIdle): add stop and reuse methods for useIdle composable Sep 25, 2025
@9romise 9romise changed the title feat(useIdle): add stop and reuse methods for useIdle composable feat(useIdle): implement Stoppable interface Sep 27, 2025
@dpbs-715 dpbs-715 requested a review from 9romise September 27, 2025 12:48
9romise
9romise previously approved these changes Sep 27, 2025
Copy link
Member

@9romise 9romise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be willing to add some test cases for your changes?

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 27, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 27, 2025

Open in StackBlitz

@vueuse/components

npm i https://pkg.pr.new/@vueuse/components@5068

@vueuse/core

npm i https://pkg.pr.new/@vueuse/core@5068

@vueuse/electron

npm i https://pkg.pr.new/@vueuse/electron@5068

@vueuse/firebase

npm i https://pkg.pr.new/@vueuse/firebase@5068

@vueuse/integrations

npm i https://pkg.pr.new/@vueuse/integrations@5068

@vueuse/math

npm i https://pkg.pr.new/@vueuse/math@5068

@vueuse/metadata

npm i https://pkg.pr.new/@vueuse/metadata@5068

@vueuse/nuxt

npm i https://pkg.pr.new/@vueuse/nuxt@5068

@vueuse/router

npm i https://pkg.pr.new/@vueuse/router@5068

@vueuse/rxjs

npm i https://pkg.pr.new/@vueuse/rxjs@5068

@vueuse/shared

npm i https://pkg.pr.new/@vueuse/shared@5068

commit: 9d5575c

@codecov
Copy link

codecov bot commented Sep 27, 2025

Codecov Report

❌ Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.58%. Comparing base (3f7f761) to head (9d5575c).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/core/useIdle/index.ts 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5068      +/-   ##
==========================================
+ Coverage   67.24%   67.58%   +0.34%     
==========================================
  Files         367      367              
  Lines       14695    14717      +22     
  Branches     2439     2453      +14     
==========================================
+ Hits         9881     9946      +65     
+ Misses       4803     4760      -43     
  Partials       11       11              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Sep 27, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Sep 28, 2025
@dpbs-715 dpbs-715 requested a review from OrbisK September 28, 2025 02:03
@dpbs-715 dpbs-715 requested a review from OrbisK September 29, 2025 08:14
@dpbs-715 dpbs-715 requested a review from 9romise September 29, 2025 08:14
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 29, 2025
@antfu antfu enabled auto-merge October 22, 2025 06:11
@antfu antfu added this pull request to the merge queue Oct 22, 2025
Merged via the queue into vueuse:main with commit 3f96a1f Oct 22, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants