Skip to content

Commit

Permalink
ref: Remove configurable state and action keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jennmueng committed Jul 14, 2020
1 parent c7f2858 commit 7c75f3b
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions packages/react/src/redux.ts
Expand Up @@ -16,29 +16,18 @@ export interface SentryEnhancerOptions {
* Return null to not send the breadcrumb.
*/
actionTransformer(action: AnyAction): AnyAction | null;
/**
* Category of the breadcrumb sent by actions. Default is 'redux.action'
*/
actionBreadcrumbCategory: string;
/**
* Type of the breadcrumb sent by actions. Default is 'info'
*/
actionBreadcrumbType: string;
/**
* The context key to pass the state to. Default is 'redux.state'
*/
stateContextKey: string;
/**
* Called on every state update, configure the Sentry Scope with the redux state.
*/
configureScopeWithState?(scope: Scope, state: any): void;
}

const ACTION_BREADCRUMB_CATEGORY = 'redux.action';
const ACTION_BREADCRUMB_TYPE = 'info';
const STATE_CONTEXT_KEY = 'redux.state';

const defaultOptions: SentryEnhancerOptions = {
actionBreadcrumbCategory: 'redux.action',
actionBreadcrumbType: 'info',
actionTransformer: action => action,
stateContextKey: 'redux.state',
// tslint:disable-next-line: no-unsafe-any
stateTransformer: state => state,
};
Expand All @@ -58,23 +47,23 @@ function createReduxEnhancer(enhancerOptions?: Partial<SentryEnhancerOptions>):

configureScope(scope => {
/* Action breadcrumbs */
const transformedAction = options.actionTransformer ? options.actionTransformer(action) : action;
const transformedAction = options.actionTransformer(action);
// tslint:disable-next-line: strict-type-predicates
if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
scope.addBreadcrumb({
category: options.actionBreadcrumbCategory,
category: ACTION_BREADCRUMB_CATEGORY,
data: transformedAction,
type: options.actionBreadcrumbType,
type: ACTION_BREADCRUMB_TYPE,
});
}

/* Set latest state to scope */
const transformedState = options.stateTransformer ? options.stateTransformer(newState) : newState;
const transformedState = options.stateTransformer(newState);
if (typeof transformedState !== 'undefined' && transformedState !== null) {
// tslint:disable-next-line: no-unsafe-any
scope.setContext(options.stateContextKey, transformedState);
scope.setContext(STATE_CONTEXT_KEY, transformedState);
} else {
scope.setContext(options.stateContextKey, null);
scope.setContext(STATE_CONTEXT_KEY, null);
}

/* Allow user to configure scope with latest state */
Expand Down

0 comments on commit 7c75f3b

Please sign in to comment.