How to sync state across browsers #986
-
Hey all, I'm working on web version of a board game, and I've got my MVP up and running using Vue 3 and Vuex 4. I want to swap out my Vuex stores for Pinia so that I can rely on its Typescript support, but I've run into an issue, and I was hoping some of you fine folk may have some suggestions: In Vuex, plugins can subscribe to a store and receive mutations objects with a In Pinia, however, there are three mutation types, and only one ( |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
And to add some context:
It's gigantic; a game state object weighs in at ~2kb which you could serialize, then ship over a WebSocket connection, and then deserialize, but the overhead is hefty.
This, honestly, feels like the closest to what I want. Force all state changes to go through actions, and that have a plugin that broadcasts actions to all connected clients. Actions with long async lifecycles could be problematic, but I could break those down into smaller, composable actions, and broadcast those ones instead of the async action. I'm not sold on this being the best approach however, as I can easily see myself or someone else directly mutating state and causing a bug that would take days to hunt down. |
Beta Was this translation helpful? Give feedback.
-
(Last self-reply, I swear): this is a good use case for #58 |
Beta Was this translation helpful? Give feedback.
-
This plugin seems to do what you want: https://www.npmjs.com/package/pinia-shared-state |
Beta Was this translation helpful? Give feedback.
This plugin seems to do what you want: https://www.npmjs.com/package/pinia-shared-state