Skip to content

Defer running the state and action transforms #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
const identity = x => x;
const getUndefined = () => {};
function createRavenMiddleware(Raven, options = {}) {
// TODO: Validate options.
const {
breadcrumbDataFromAction = getUndefined,
actionTransformer = identity,
stateTransformer = identity,
breadcrumbCategory = "redux-action"
} = options;
Raven.setDataCallback((data, original) => {
data.extra.lastAction = actionTransformer(data.extra.lastAction);
data.extra.state = stateTransformer(data.extra.state);
return original ? original(data) : data;
});
return store => {
// Record the initial state in case we crash before the first action
// succeeds.
Raven.setExtraContext({ state: stateTransformer(store.getState()) });
// TODO: This does not currently work.
Raven.setExtraContext({ state: store.getState() });

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

// Set the action as context in case we crash in the reducer.
const extra = { lastAction: actionTransformer(action) };
const extra = { lastAction: action };
Raven.context({ extra }, () => next(action));

// Set the last action and state as context in case we crash before
// the next action is dispatched.
Raven.setExtraContext({
lastAction: actionTransformer(action),
state: stateTransformer(store.getState())
lastAction: action,
state: store.getState()
});
};
};
Expand Down
3 changes: 1 addition & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ describe("raven-for-redux", function() {
)
);
});
// TODO: Issue #6
xit("does not transform the state or action until an exception is encountered", function() {
it("does not transform the state or action until an exception is encountered", function() {
this.store.dispatch({ type: "INCREMENT" });
expect(this.stateTransformer).not.toHaveBeenCalled();
expect(this.actionTransformer).not.toHaveBeenCalled();
Expand Down