Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow not unwrapping refs when using store #2504

Closed
coolCucumber-cat opened this issue Nov 23, 2023 · 1 comment
Closed

Allow not unwrapping refs when using store #2504

coolCucumber-cat opened this issue Nov 23, 2023 · 1 comment

Comments

@coolCucumber-cat
Copy link

What problem is this solving

So when you use a store, it wraps it in a reactive, which is helpful since you don't have to use .value and it means composition and options stores are the same. But it's also really annoying because it's not what you expect it to be if you're returning refs and you can't destructure them. It's quite annoying to have to use storeToRefs or computed when it's not really necessary.

Proposed solution

Solution 1: Allow passing an options object when you create the store, including the two current options, plus an option to not unwrap refs. This would be harder because wrapping it is done when you define it, at least that's what it looks like when I look at the source code.

Solution 2: Make this an option when you define the store instead of when you create it. This is easier, but it's probably not as good since it isn't obvious when you use it, you'd have to look at the definition or maybe the types.

Describe alternatives you've considered

No response

@posva
Copy link
Member

posva commented Nov 23, 2023

For now, there is no intention of shipping this feature with the existing ones because it makes things different when using the store, while it is not explicit why things are not unwrapped anymore (still same useStore() call). In practice, I've played with both ideas, and I rarely extract refs from the store, I use the store directly, as a whole, as a service. You don't need to use storeToRefs().
It's also worth noting that this can be implemented in user land with a custom defineStore that calls storeToRefs().

That being said, I don't want to give up the idea yet completely, so I will move it to Discussions and see if the community comes up with other arguments

@vuejs vuejs locked and limited conversation to collaborators Nov 23, 2023
@posva posva converted this issue into discussion #2506 Nov 23, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

2 participants