Skip to content

feat(vue): Apply stateTransformer to attachments in Pinia Plugin #16034

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

Merged
merged 6 commits into from
Apr 14, 2025

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Apr 11, 2025

Continuation of #14474

As the store logic changed a bit, I changed the PR a bit. The getAllStores function can now receive the stateTransformer and apply it.

Closes #14441

@s1gr1d s1gr1d requested a review from onurtemizkan April 11, 2025 11:00
@s1gr1d s1gr1d marked this pull request as ready for review April 11, 2025 11:00
@s1gr1d s1gr1d self-assigned this Apr 11, 2025
@@ -28,14 +28,20 @@ export const createSentryPiniaPlugin: (options?: SentryPiniaPluginOptions) => Pi
},
) => {
const plugin: PiniaPlugin = ({ store, pinia }) => {
const getAllStoreStates = (): Record<string, unknown> => {
const getAllStoreStates = (
stateTransformer?: SentryPiniaPluginOptions['stateTransformer'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@s1gr1d s1gr1d requested a review from AbhiPrasad April 14, 2025 08:03
@s1gr1d s1gr1d merged commit 458fa07 into develop Apr 14, 2025
152 checks passed
@s1gr1d s1gr1d deleted the sig/pinia-attachments branch April 14, 2025 15:27
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.

Apply stateTransformer to Attachments in createSentryPiniaPlugin
3 participants