From e00cabdefb158655ea5d86f0b50202834dadd5c1 Mon Sep 17 00:00:00 2001 From: Jennarong Muengtaweepongsa Date: Tue, 14 Jul 2020 14:44:11 +0700 Subject: [PATCH] ref: Remove configurable state and action keys --- packages/react/src/redux.ts | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/packages/react/src/redux.ts b/packages/react/src/redux.ts index 30cdc3c2db1a..8fa1547f84b6 100644 --- a/packages/react/src/redux.ts +++ b/packages/react/src/redux.ts @@ -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, }; @@ -58,23 +47,23 @@ function createReduxEnhancer(enhancerOptions?: Partial): 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 */