Skip to content

Commit 52a45f6

Browse files
authored
Merge pull request #8 from captbaritone/issue-6
Defer running the state and action transforms
2 parents 181d2bc + 04cad54 commit 52a45f6

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
const identity = x => x;
22
const getUndefined = () => {};
33
function createRavenMiddleware(Raven, options = {}) {
4+
// TODO: Validate options.
45
const {
56
breadcrumbDataFromAction = getUndefined,
67
actionTransformer = identity,
78
stateTransformer = identity,
89
breadcrumbCategory = "redux-action"
910
} = 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+
});
1016
return store => {
1117
// Record the initial state in case we crash before the first action
1218
// succeeds.
13-
Raven.setExtraContext({ state: stateTransformer(store.getState()) });
19+
// TODO: This does not currently work.
20+
Raven.setExtraContext({ state: store.getState() });
1421

1522
return next => action => {
1623
// Log the action taken to Raven so that we have narrative context in our
@@ -22,14 +29,14 @@ function createRavenMiddleware(Raven, options = {}) {
2229
});
2330

2431
// Set the action as context in case we crash in the reducer.
25-
const extra = { lastAction: actionTransformer(action) };
32+
const extra = { lastAction: action };
2633
Raven.context({ extra }, () => next(action));
2734

2835
// Set the last action and state as context in case we crash before
2936
// the next action is dispatched.
3037
Raven.setExtraContext({
31-
lastAction: actionTransformer(action),
32-
state: stateTransformer(store.getState())
38+
lastAction: action,
39+
state: store.getState()
3340
});
3441
};
3542
};

index.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ describe("raven-for-redux", function() {
119119
)
120120
);
121121
});
122-
// TODO: Issue #6
123-
xit("does not transform the state or action until an exception is encountered", function() {
122+
it("does not transform the state or action until an exception is encountered", function() {
124123
this.store.dispatch({ type: "INCREMENT" });
125124
expect(this.stateTransformer).not.toHaveBeenCalled();
126125
expect(this.actionTransformer).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)