feat(vue): Apply stateTransformer to attachments in Pinia Plugin#16034
Merged
feat(vue): Apply stateTransformer to attachments in Pinia Plugin#16034
Conversation
2 tasks
AbhiPrasad
reviewed
Apr 11, 2025
packages/vue/src/pinia.ts
Outdated
| const plugin: PiniaPlugin = ({ store, pinia }) => { | ||
| const getAllStoreStates = (): Record<string, unknown> => { | ||
| const getAllStoreStates = ( | ||
| stateTransformer?: SentryPiniaPluginOptions['stateTransformer'], |
Contributor
There was a problem hiding this comment.
m: The default options need to be destructured into the options object so that people can provide only a few of the options but still get the rest of the defaults.
// declare the type with no optional fields
type SentryPiniaPluginOptions = {
attachPiniaState: boolean;
addBreadcrumbs: boolean;
actionTransformer: (action: string) => any;
stateTransformer: (state: Record<string, unknown>) => any;
};
const DEFAULT_PINIA_PLUGIN_OPTIONS: SentryPiniaPluginOptions = {
attachPiniaState: true,
addBreadcrumbs: true,
actionTransformer: action => action,
stateTransformer: state => state,
}
// make sure user options are `Partial<SentryPiniaPluginOptions>` so that they can define
// a subset of options they want to override.
export const createSentryPiniaPlugin: = (userOptions: Partial<SentryPiniaPluginOptions> = {}): PiniaPlugin => {
const { attachPiniaState, addBreadcrumbs, actionTransformer, stateTransformer } = { ...userOptions, ...DEFAULT_PINIA_PLUGIN_OPTIONS } as SentryPiniaPluginOptions;This also means we don't need to pass in stateTransformer into getAllStoreStates, because it can grab it from the closure.
Member
Author
There was a problem hiding this comment.
I know that stateTransformer could be grabbed from the closure here but I made it an argument of the function so it's more explicit that a stateTransformer is used when calling getAllStates. Otherwise it would be a weird side effect you only see when looking at the function code.
But good catch with the destructuring - right now it's either the users' object or the default one.
AbhiPrasad
approved these changes
Apr 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuation of #14474
As the store logic changed a bit, I changed the PR a bit. The
getAllStoresfunction can now receive thestateTransformerand apply it.Closes #14441