Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Support for reactive objects #1

Closed
cyruscollier opened this issue Mar 17, 2023 · 3 comments
Closed

Support for reactive objects #1

cyruscollier opened this issue Mar 17, 2023 · 3 comments
Assignees

Comments

@cyruscollier
Copy link

Thanks for making this plugin! It's simple and useful.

One thing I noticed when using it was that I couldn't use reactive() objects in the state, because the reactivity breaks when the state syncs with the storage:

https://github.com/BreizhReloaded/unstorage-pinia-plugin/blob/master/src/plugin.ts#L7

Because Object.assign() only does a shallow copy, nested reactive objects get overwritten as plain objects. I think to support a deep syncing of the state, you'd have to loop through the state entries itself and call Object.assign() on each one (if it's in the filter list), or it's possible that Pinia's built-in Patch mechanism may do the same thing: https://pinia.vuejs.org/core-concepts/state.html#replacing-the-state

Happy to submit a PR if you think either of these approaches make sense.

@BreizhReloaded
Copy link
Owner

Hello Cyrus,

Sorry I took time to answer: I was looked out my GitHub account due to 2FA issues.

It's a really good point. Helper function $patch() seems to be the solution, don't you think? If you're happy with it, I can do it on my side. I'll use the opportunity to update some dependencies!

Thanks!

@BreizhReloaded BreizhReloaded self-assigned this Mar 23, 2023
@cyruscollier
Copy link
Author

Yeah, let's use $patch(). That'll have the advantage of giving more visibility in Vue devtools when the state is syncing back from storage.

@BreizhReloaded
Copy link
Owner

Updated and fixed! Let me know if you notice anything.

By the way, package is moving here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants