1
1
const identity = x => x ;
2
2
const getUndefined = ( ) => { } ;
3
3
function createRavenMiddleware ( Raven , options = { } ) {
4
+ // TODO: Validate options.
4
5
const {
5
6
breadcrumbDataFromAction = getUndefined ,
6
7
actionTransformer = identity ,
7
8
stateTransformer = identity ,
8
9
breadcrumbCategory = "redux-action"
9
10
} = options ;
11
+ Raven . setDataCallback ( ( data , original ) => {
12
+ data . extra . lastAction = actionTransformer ( data . extra . lastAction ) ;
13
+ data . extra . state = stateTransformer ( data . extra . state ) ;
14
+ return original ? original ( data ) : data ;
15
+ } ) ;
10
16
return store => {
11
17
// Record the initial state in case we crash before the first action
12
18
// succeeds.
13
- Raven . setExtraContext ( { state : stateTransformer ( store . getState ( ) ) } ) ;
19
+ // TODO: This does not currently work.
20
+ Raven . setExtraContext ( { state : store . getState ( ) } ) ;
14
21
15
22
return next => action => {
16
23
// Log the action taken to Raven so that we have narrative context in our
@@ -22,14 +29,14 @@ function createRavenMiddleware(Raven, options = {}) {
22
29
} ) ;
23
30
24
31
// Set the action as context in case we crash in the reducer.
25
- const extra = { lastAction : actionTransformer ( action ) } ;
32
+ const extra = { lastAction : action } ;
26
33
Raven . context ( { extra } , ( ) => next ( action ) ) ;
27
34
28
35
// Set the last action and state as context in case we crash before
29
36
// the next action is dispatched.
30
37
Raven . setExtraContext ( {
31
- lastAction : actionTransformer ( action ) ,
32
- state : stateTransformer ( store . getState ( ) )
38
+ lastAction : action ,
39
+ state : store . getState ( )
33
40
} ) ;
34
41
} ;
35
42
} ;
0 commit comments