From 5220d6be007810230bdc2e4c5e42e178dbdfd0fc Mon Sep 17 00:00:00 2001 From: Jennarong Muengtaweepongsa Date: Mon, 13 Jul 2020 16:53:20 +0700 Subject: [PATCH] ref: Use context instead of extra for redux state. --- packages/react/src/redux.ts | 11 ++++++----- packages/react/test/redux.test.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/react/src/redux.ts b/packages/react/src/redux.ts index 0039209e41c1..30cdc3c2db1a 100644 --- a/packages/react/src/redux.ts +++ b/packages/react/src/redux.ts @@ -25,9 +25,9 @@ export interface SentryEnhancerOptions { */ actionBreadcrumbType: string; /** - * The extra key to pass the state to. Default is 'redux.state' + * The context key to pass the state to. Default is 'redux.state' */ - stateExtraKey: string; + stateContextKey: string; /** * Called on every state update, configure the Sentry Scope with the redux state. */ @@ -38,7 +38,7 @@ const defaultOptions: SentryEnhancerOptions = { actionBreadcrumbCategory: 'redux.action', actionBreadcrumbType: 'info', actionTransformer: action => action, - stateExtraKey: 'redux.state', + stateContextKey: 'redux.state', // tslint:disable-next-line: no-unsafe-any stateTransformer: state => state, }; @@ -71,9 +71,10 @@ function createReduxEnhancer(enhancerOptions?: Partial): /* Set latest state to scope */ const transformedState = options.stateTransformer ? options.stateTransformer(newState) : newState; if (typeof transformedState !== 'undefined' && transformedState !== null) { - scope.setExtra(options.stateExtraKey, transformedState); + // tslint:disable-next-line: no-unsafe-any + scope.setContext(options.stateContextKey, transformedState); } else { - scope.setExtra(options.stateExtraKey, undefined); + scope.setContext(options.stateContextKey, null); } /* Allow user to configure scope with latest state */ diff --git a/packages/react/test/redux.test.ts b/packages/react/test/redux.test.ts index 4e734a316753..1fd4da3230c6 100644 --- a/packages/react/test/redux.test.ts +++ b/packages/react/test/redux.test.ts @@ -6,19 +6,19 @@ import * as Redux from 'redux'; import { createReduxEnhancer } from '../src/redux'; const mockAddBreadcrumb = jest.fn(); -const mockSetExtra = jest.fn(); +const mockSetContext = jest.fn(); jest.mock('@sentry/minimal', () => ({ configureScope: (callback: (scope: any) => Partial) => callback({ addBreadcrumb: mockAddBreadcrumb, - setExtra: mockSetExtra, + setContext: mockSetContext, }), })); afterEach(() => { mockAddBreadcrumb.mockReset(); - mockSetExtra.mockReset(); + mockSetContext.mockReset(); }); describe('createReduxEnhancer', () => { @@ -60,7 +60,7 @@ describe('createReduxEnhancer', () => { const updateAction = { type: ACTION_TYPE, newValue: 'updated' }; store.dispatch(updateAction); - expect(mockSetExtra).toBeCalledWith('redux.state', { + expect(mockSetContext).toBeCalledWith('redux.state', { value: 'updated', }); }); @@ -81,7 +81,7 @@ describe('createReduxEnhancer', () => { Redux.createStore((state = initialState) => state, enhancer); - expect(mockSetExtra).toBeCalledWith('redux.state', { + expect(mockSetContext).toBeCalledWith('redux.state', { superSecret: 'REDACTED', value: 123, }); @@ -100,7 +100,7 @@ describe('createReduxEnhancer', () => { Redux.createStore((state = initialState) => state, enhancer); // Check that state is cleared - expect(mockSetExtra).toBeCalledWith('redux.state', undefined); + expect(mockSetContext).toBeCalledWith('redux.state', null); }); it('transforms actions', () => {