Skip to content

Commit

Permalink
ref: Redux as devDependency and use @sentry/minimal instead of browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng committed Jul 10, 2020
1 parent 688dc86 commit 661454e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
5 changes: 2 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@sentry/browser": "5.19.0",
"@sentry/minimal": "5.19.0",
"@sentry/types": "5.19.0",
"@sentry/utils": "5.19.0",
"hoist-non-react-statics": "^3.3.2",
Expand All @@ -26,9 +27,6 @@
"react": "15.x || 16.x",
"react-dom": "15.x || 16.x"
},
"optionalDependencies": {
"redux": ">=1.0.0"
},
"devDependencies": {
"@testing-library/react": "^10.0.6",
"@testing-library/react-hooks": "^3.3.0",
Expand All @@ -42,6 +40,7 @@
"react": "^16.0.0",
"react-dom": "^16.0.0",
"react-test-renderer": "^16.13.1",
"redux": "^4.0.5",
"rimraf": "^2.6.3",
"tslint": "^5.16.0",
"tslint-react": "^5.0.0",
Expand Down
24 changes: 11 additions & 13 deletions packages/react/src/redux.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import * as Sentry from '@sentry/browser';
import * as Redux from 'redux';
import { configureScope } from '@sentry/minimal';
import { Scope } from '@sentry/types';
import { Action, AnyAction, PreloadedState, Reducer, StoreEnhancer, StoreEnhancerStoreCreator } from 'redux';

export interface SentryEnhancerOptions {
/**
Expand All @@ -14,7 +15,7 @@ export interface SentryEnhancerOptions {
* Use this to remove any private data before sending it to Sentry.
* Return null to not send the breadcrumb.
*/
actionTransformer(action: Redux.AnyAction): Redux.AnyAction | null;
actionTransformer(action: AnyAction): AnyAction | null;
/**
* Category of the breadcrumb sent by actions. Default is 'redux.action'
*/
Expand All @@ -30,7 +31,7 @@ export interface SentryEnhancerOptions {
/**
* Called on every state update, configure the Sentry Scope with the redux state.
*/
configureScopeWithState?(scope: Sentry.Scope, state: any): void;
configureScopeWithState?(scope: Scope, state: any): void;
}

const defaultOptions: SentryEnhancerOptions = {
Expand All @@ -42,23 +43,20 @@ const defaultOptions: SentryEnhancerOptions = {
stateTransformer: state => state,
};

function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): Redux.StoreEnhancer {
function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>): StoreEnhancer {
const options = {
...defaultOptions,
...enhancerOptions,
};

return (next: Redux.StoreEnhancerStoreCreator): Redux.StoreEnhancerStoreCreator => <
S = any,
A extends Redux.Action = Redux.AnyAction
>(
reducer: Redux.Reducer<S, A>,
initialState?: Redux.PreloadedState<S>,
return (next: StoreEnhancerStoreCreator): StoreEnhancerStoreCreator => <S = any, A extends Action = AnyAction>(
reducer: Reducer<S, A>,
initialState?: PreloadedState<S>,
) => {
const sentryReducer: Redux.Reducer<S, A> = (state, action): S => {
const sentryReducer: Reducer<S, A> = (state, action): S => {
const newState = reducer(state, action);

Sentry.configureScope(scope => {
configureScope(scope => {
/* Action breadcrumbs */
const transformedAction = options.actionTransformer ? options.actionTransformer(action) : action;
// tslint:disable-next-line: strict-type-predicates
Expand Down
5 changes: 3 additions & 2 deletions packages/react/test/redux.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Sentry from '@sentry/browser';
// tslint:disable-next-line: no-implicit-dependencies
import * as Sentry from '@sentry/minimal';
import { Scope } from '@sentry/types';
import * as Redux from 'redux';

Expand All @@ -7,7 +8,7 @@ import { createReduxEnhancer } from '../src/redux';
const mockAddBreadcrumb = jest.fn();
const mockSetExtra = jest.fn();

jest.mock('@sentry/browser', () => ({
jest.mock('@sentry/minimal', () => ({
configureScope: (callback: (scope: any) => Partial<Scope>) =>
callback({
addBreadcrumb: mockAddBreadcrumb,
Expand Down

0 comments on commit 661454e

Please sign in to comment.