Skip to content

Comments

feat(refManualReset): new function#4644

Merged
antfu merged 15 commits intovueuse:mainfrom
phk422:feature/refManualReset
Sep 10, 2025
Merged

feat(refManualReset): new function#4644
antfu merged 15 commits intovueuse:mainfrom
phk422:feature/refManualReset

Conversation

@phk422
Copy link
Contributor

@phk422 phk422 commented Mar 5, 2025

Close: #4564

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Mar 5, 2025
@phk422 phk422 force-pushed the feature/refManualReset branch 2 times, most recently from 34916dd to 77458bf Compare March 5, 2025 08:52
@phk422 phk422 force-pushed the feature/refManualReset branch from 77458bf to 636541c Compare March 5, 2025 08:54
@ferferga
Copy link
Member

Instead of a new function... Why we don't adapt the current one so, when an undefined or null timeout is passed, it does what's proposed in the issue?

@phk422
Copy link
Contributor Author

phk422 commented Mar 14, 2025

Instead of a new function... Why we don't adapt the current one so, when an undefined or null timeout is passed, it does what's proposed in the issue?

Thank you for your suggestion! Considering that the semantics of refAutoRest are clearly tied to "Auto," directly modifying it might not be appropriate. Therefore, I have added a separate method. Additionally, we can use the refReset method and differentiate between automatic and manual modes through parameters. If you agree, I can further refine this solution.

@chojnicki
Copy link

Considering that the semantics of refAutoRest are clearly tied to "Auto," directly modifying it might not be appropriat

I totally agree with that. I'm actually surprised that there is function for auto option, but not manual one (refDefault is something different) :P In my opinion ideally there should be single function for both, where auto with timer would be just optional option. If not, refManualReset is still good option. But adding manual option for refAutoReset is really not intuitive.

@Rhilip
Copy link

Rhilip commented Apr 22, 2025

When defaultValue is object, the reset function will not work.

try this example . click Update Ref btn then Reset Ref btn, the msg.value will not reset.

image

@ilyaliao
Copy link
Member

ilyaliao commented Apr 22, 2025

I’d personally like refManualReset to mirror refAutoReset as much as possible.

They can live as separate composables, but their API and internal structure should be very similar.

@phk422
Copy link
Contributor Author

phk422 commented Apr 23, 2025

I’d personally like refManualReset to mirror refAutoReset as much as possible.

They can live as separate composables, but their API and internal structure should be very similar.

I have updated it. Kindly review.

@jeffreyvdhondel
Copy link

I would really love this feature for reseting an ref back to its default value.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 2, 2025

Open in StackBlitz

@vueuse/components

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

@vueuse/core

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

@vueuse/electron

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

@vueuse/firebase

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

@vueuse/integrations

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

@vueuse/math

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

@vueuse/metadata

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

@vueuse/nuxt

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

@vueuse/router

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

@vueuse/rxjs

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

@vueuse/shared

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

commit: 5d64346

@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 Aug 3, 2025
@phk422 phk422 requested a review from ilyaliao August 5, 2025 05:12
@phk422 phk422 requested a review from ilyaliao August 15, 2025 01:08
@phk422
Copy link
Contributor Author

phk422 commented Aug 21, 2025

Hi @antfu 👋

I'm just following up on this PR which was recently approved. Whenever you have a moment, could you please take a look and consider merging it?

I'm really excited to contribute to VueUse and believe the function will be a handy

@antfu antfu added the direction: approved The direction of feature/change is approved by the team. May require some small changes. label Sep 8, 2025
@antfu
Copy link
Member

antfu commented Sep 8, 2025

OK, I am good to have this new function if people found it useful

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 8, 2025
@phk422 phk422 requested a review from antfu September 9, 2025 07:59
@phk422 phk422 force-pushed the feature/refManualReset branch from 820b2dd to 2321055 Compare September 9, 2025 08:03
antfu
antfu previously approved these changes Sep 9, 2025
OrbisK
OrbisK previously approved these changes Sep 9, 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.

How about including some test cases as well?

@phk422 phk422 dismissed stale reviews from OrbisK and antfu via 70b4cfd September 10, 2025 01:27
@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 10, 2025
@antfu antfu added this pull request to the merge queue Sep 10, 2025
Merged via the queue into vueuse:main with commit 81bb3cd Sep 10, 2025
10 checks passed
@isimehmeti
Copy link
Contributor

A deep ref option would have been nice, as it’s especially useful for forms or lists.

@phk422 phk422 deleted the feature/refManualReset branch October 23, 2025 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

direction: approved The direction of feature/change is approved by the team. May require some small changes. enhancement New feature or request lgtm This PR has been approved by a maintainer new function size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refManualReset | reset ref to inital value

10 participants