Skip to content
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

Vike pinia #64

Closed
wants to merge 5 commits into from
Closed

Vike pinia #64

wants to merge 5 commits into from

Conversation

4350pChris
Copy link
Member

@4350pChris 4350pChris commented Jan 9, 2024

Integration of pinia into vike-vue.
See vikejs/vike#1374

I decided to follow the other repositories and create a package folder for this. We should probably move the existing code into that folder as well, but for now I let it be so as not to have too many changes.

I'd appreciate general feedback on my approach here - is having new hooks the way to go here? Is it ok to provide a default onCreateApp hook here and expect the user to provide their own, while importing the one from this package like in the example +onCreateApp.ts?

I do have one issue with this implementation - other stores / data fetching tools like tan-query need to hook into the same place, which becomes unwieldy. So my solution would be to make the hooks I introduced more general - maybe call them onAfterRenderSSRApp (dehydrate) and onBeforeMountApp (hydrate) or something. But then I run into two issues - firstly, onAfterRenderSSRApp would have to return an object that we add to the pageContext that onRenderHtml returns, as we need to leave it up to the package what the property is called that will be sent to the client, otherwise we need to include it in vike-vue's passToClient. That would, however, expose another low-level hook that can be used to directly set properties on pageContext. Secondly, we don't want to exclude users from using multiple state management libraries. I for myself use both pinia and vue-query. If they both use the aforementioned hooks, we'd need some way of orchestrating that or go and make this a proper pub / sub where any function can register to get notified by these hooks. In general I think it would be very beneficial if we don't have to touch vike-vue's base package for any other state management tool, as no normal user can do this, thus preventing any packages outside of this repository to be implemented in the same way.

I hope this is written in a way that's not too confusing.

Also I'll try to write some tests when I find the time.

Signed-off-by: Chris-Robin Ennen <[email protected]>
Signed-off-by: Chris-Robin Ennen <[email protected]>
Signed-off-by: Chris-Robin Ennen <[email protected]>
Signed-off-by: Chris-Robin Ennen <[email protected]>
@4350pChris 4350pChris closed this Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant