MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / sentryWrapReducer

Function sentryWrapReducer

packages/react/src/redux.ts:122–166  ·  view source on GitHub ↗
(reducer: Reducer<S, A>)

Source from the content-addressed store, hash-verified

120 });
121
122 function sentryWrapReducer(reducer: Reducer<S, A>): Reducer<S, A> {
123 return (state, action): S => {
124 const newState = reducer(state, action);
125
126 const scope = getCurrentScope();
127
128 /* Action breadcrumbs */
129 const transformedAction = options.actionTransformer(action);
130 if (typeof transformedAction !== 'undefined' && transformedAction !== null) {
131 addBreadcrumb({
132 category: ACTION_BREADCRUMB_CATEGORY,
133 data: transformedAction,
134 type: ACTION_BREADCRUMB_TYPE,
135 });
136 }
137
138 /* Set latest state to scope */
139 const transformedState = options.stateTransformer(newState);
140 if (typeof transformedState !== 'undefined' && transformedState !== null) {
141 const client = getClient();
142 const options = client?.getOptions();
143 const normalizationDepth = options?.normalizeDepth || 3; // default state normalization depth to 3
144
145 // Set the normalization depth of the redux state to the configured `normalizeDepth` option or a sane number as a fallback
146 const newStateContext = { state: { type: 'redux', value: transformedState } };
147 setNormalizationDepthOverrideHint(
148 newStateContext,
149 3 + // 3 layers for `state.value.transformedState`
150 normalizationDepth, // rest for the actual state
151 );
152
153 scope.setContext('state', newStateContext);
154 } else {
155 scope.setContext('state', null);
156 }
157
158 /* Allow user to configure scope with latest state */
159 const { configureScopeWithState } = options;
160 if (typeof configureScopeWithState === 'function') {
161 configureScopeWithState(scope, newState);
162 }
163
164 return newState;
165 };
166 }
167
168 const store = next(sentryWrapReducer(reducer), initialState);
169

Callers 1

createReduxEnhancerFunction · 0.85

Calls 9

getClientFunction · 0.90
reducerFunction · 0.85
addBreadcrumbFunction · 0.85
actionTransformerMethod · 0.80
stateTransformerMethod · 0.80
setContextMethod · 0.80
getOptionsMethod · 0.65
getCurrentScopeFunction · 0.50

Tested by

no test coverage detected