Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1def9a7

Browse files
committed
Implcit binding + lazy evaluation instead of storing context in Raven
1 parentb6a148d commit1def9a7

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

‎index.js‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ function createRavenMiddleware(Raven, options = {}) {
88
stateTransformer=identity,
99
breadcrumbCategory="redux-action"
1010
}=options;
11-
Raven.setDataCallback((data,original)=>{
12-
data.extra.lastAction=actionTransformer(data.extra.lastAction);
13-
data.extra.state=stateTransformer(data.extra.state);
14-
returnoriginal ?original(data) :data;
15-
});
11+
1612
returnstore=>{
17-
// Record the initial state in case we crash before the first action
18-
// succeeds.
19-
// TODO: This does not currently work.
20-
Raven.setExtraContext({state:store.getState()});
13+
letlastAction;
14+
15+
Raven.setDataCallback((data,original)=>{
16+
data.extra.lastAction=actionTransformer(lastAction);
17+
data.extra.state=stateTransformer(store.getState());
18+
returnoriginal ?original(data) :data;
19+
});
2120

2221
returnnext=>action=>{
2322
// Log the action taken to Raven so that we have narrative context in our
@@ -28,17 +27,8 @@ function createRavenMiddleware(Raven, options = {}) {
2827
data:breadcrumbDataFromAction(action)
2928
});
3029

31-
// Set the action as context in case we crash in the reducer.
32-
constextra={lastAction:action};
33-
constreturnValue=Raven.context({ extra},()=>next(action));
34-
35-
// Set the last action and state as context in case we crash before
36-
// the next action is dispatched.
37-
Raven.setExtraContext({
38-
lastAction:action,
39-
state:store.getState()
40-
});
41-
returnreturnValue;
30+
lastAction=action;
31+
returnnext(action);
4232
};
4333
};
4434
}

‎index.test.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ const { createStore, applyMiddleware } = require("redux");
44

55
Raven.config("https://5d5bf17b1bed4afc9103b5a09634775e@sentry.io/146969",{
66
allowDuplicates:true
7-
});
7+
}).install();
88

99
constreducer=(previousState=0,action)=>{
1010
switch(action.type){
1111
case"THROW":
12-
thrownewError("Reducer error");
12+
// Raven does not seem to be able to capture global exceptions in Jest tests.
13+
// So we explicitly wrap this error in a Raven context.
14+
Raven.context(()=>{
15+
thrownewError("Reducer error");
16+
});
1317
case"INCREMENT":
1418
returnpreviousState+1;
1519
case"DOUBLE":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp