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

feat: custom serializer #34

Merged
merged 11 commits into from
Dec 13, 2023
Merged

feat: custom serializer #34

merged 11 commits into from
Dec 13, 2023

Conversation

wobsoriano
Copy link
Owner

@wobsoriano wobsoriano commented Dec 4, 2023

This PR introduces an option to utilize a custom serializer for serializing the store state before it is transmitted using broadcast-channel. This is essential because the Pinia store state is a proxy, and broadcast-channel only supports the transmission of POJOs or strings. By default, it uses JSON.stringify/JSON.parse for serialization.

Additionally, this update eliminates the need for individual state watches, opting instead for the built-instore.$subscribe feature provided by Pinia.

Closes #29 but might reintroduce #27.

Example usage:

import { PiniaSharedState } from 'pinia-shared-state'
import { parse, stringify } from 'zipson' // Choose whatever suits your project.

pinia.use(
  PiniaSharedState({
    serializer: {
      serialize: stringify,
      deserialize: parse,
    },
  }),
)

@wobsoriano wobsoriano merged commit 884bb2a into main Dec 13, 2023
@wobsoriano wobsoriano deleted the custom-serializer branch December 13, 2023 17:26
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.

stringify non-POJOS error
1 participant