Uh oh!
There was an error while loading. Please reload this page.
feat(vue): Apply stateTransformer to attachments in Pinia Plugin - #16034
Conversation
| const plugin: PiniaPlugin = ({ store, pinia }) => { | ||
| const getAllStoreStates = (): Record<string, unknown> => { | ||
| const getAllStoreStates = ( | ||
| stateTransformer?: SentryPiniaPluginOptions['stateTransformer'], |
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 fieldstypeSentryPiniaPluginOptions={attachPiniaState: boolean;addBreadcrumbs: boolean;actionTransformer: (action: string)=>any;stateTransformer: (state: Record<string,unknown>)=>any;};constDEFAULT_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.exportconstcreateSentryPiniaPlugin: =(userOptions: Partial<SentryPiniaPluginOptions>={}): PiniaPlugin=>{const{ attachPiniaState, addBreadcrumbs, actionTransformer, stateTransformer }={ ...userOptions, ...DEFAULT_PINIA_PLUGIN_OPTIONS}asSentryPiniaPluginOptions;This also means we don't need to pass in stateTransformer into getAllStoreStates, because it can grab it from the closure.
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.
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