Skip to content

Commit a7db709

Browse files
committed
Use XO as linter, remove unused files, bump version to 1.3.0 and reorder new error handler params
1 parent 858f613 commit a7db709

File tree

8 files changed

+50
-44
lines changed

8 files changed

+50
-44
lines changed

.babelrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.npmignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
node_modules
2-
lib
3-
test
42
logs
53
*.log
6-
.babelrc
4+
.travis.yml
5+
test.js

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sudo": false,
3+
"language": "node_js",
4+
"node_js": 6
5+
}

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# redux-catch
22
Error catcher middleware for Redux reducers and middlewares.
33

4+
[![Build Status](https://travis-ci.org/sergiodxa/redux-catch.svg?branch=master)](https://travis-ci.org/zeit/micro)
5+
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
6+
47
## API
58
### Apply middleware
69
```javascript
@@ -10,11 +13,11 @@ import reduxCatch from 'redux-catch';
1013

1114
import reducer from './reducer';
1215

13-
function errorHandler(error, getState, dispatch, lastAction) {
16+
function errorHandler(error, getState, lastAction, dispatch) {
1417
console.error(error);
1518
console.debug('current state', getState());
1619
console.debug('last action was', lastAction);
17-
// optionally dispatch an action due to the error using the dispatch param
20+
// optionally dispatch an action due to the error using the dispatch parameter
1821
}
1922

2023
const store = createStore(reducer, applyMiddleware(
@@ -62,9 +65,10 @@ Now `redux-catch` will start to send the errors of your reducers and middlewares
6265
You can also add the state data as extra data for your errors so you can know the state at the moment of the error.
6366

6467
```javascript
65-
function errorHandler(error, getState) {
68+
function errorHandler(error, getState, action) {
6669
Raven.context({
6770
state: getState(),
71+
action,
6872
});
6973
Raven.captureException(error);
7074
}

index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
function middlewareFactory(errorHandler) {
2-
return function middlewareStore(store) {
3-
return function middlewareNext(next) {
4-
return function middlewareAction(action) {
2+
return function (store) {
3+
return function (next) {
4+
return function (action) {
55
try {
66
return next(action);
7-
} catch (error) {
8-
errorHandler(error, store.getState, store.dispatch, action);
9-
return error;
7+
} catch (err) {
8+
errorHandler(err, store.getState, action, store.dispatch);
9+
return err;
1010
}
1111
};
1212
};

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "redux-catch",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Error catcher middleware for Redux reducers and middlewares",
55
"main": "index.js",
66
"scripts": {
7-
"lint": "eslint index.js",
7+
"fix": "xo --fix index.js test.js",
8+
"lint": "xo index.js",
89
"pretest": "npm run lint",
910
"test": "node test.js | tap-spec",
1011
"prepublish": "npm run test"
@@ -19,18 +20,18 @@
1920
"catch",
2021
"middleware"
2122
],
22-
"author": "Sergio Daniel Xalambrí <sergio@xalambri.com.ar> (http://sergio.xalambri.com.ar/)",
23+
"author": "Sergio Daniel Xalambrí <sergiodxa@gmail.com> (http://sergio.xalambri.xyz/)",
2324
"license": "MIT",
2425
"bugs": {
2526
"url": "https://github.com/sergiodxa/redux-catch/issues"
2627
},
27-
"homepage": "http://sergio.xalambri.com.ar/redux-catch",
28+
"homepage": "http://sergio.xalambri.xyz/redux-catch",
2829
"devDependencies": {
29-
"eslint": "2.7.0",
30-
"eslint-config-airbnb": "7.0.0",
31-
"eslint-plugin-jsx-a11y": "0.6.2",
32-
"eslint-plugin-react": "4.3.0",
3330
"tap-spec": "4.1.1",
34-
"tape": "4.5.1"
31+
"tape": "4.6.2",
32+
"xo": "0.17.1"
33+
},
34+
"xo": {
35+
"space": true
3536
}
3637
}

test.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
const test = require('tape');
22
const middleware = require('./index.js');
33

4+
function getState() {
5+
return 'test';
6+
}
7+
8+
function dispatch() {
9+
return dispatch;
10+
}
11+
412
const mockedMiddlewareAPI = {
5-
getState: function getState() {
6-
return 'test';
7-
},
8-
dispatch: function dispatch() {
9-
return dispatch;
10-
}
13+
getState,
14+
dispatch
1115
};
1216

1317
const baseError = new Error('There was an error.');
1418

1519
const errorAction = {
16-
type: 'ERROR',
20+
type: 'ERROR'
1721
};
1822

1923
function errorCase(t) {
@@ -23,7 +27,7 @@ function errorCase(t) {
2327

2428
t.plan(5);
2529

26-
function errorHandler(error, getState, dispatch, action) {
30+
function errorHandler(error, getState, action, dispatch) {
2731
t.ok(
2832
error.message === baseError.message,
2933
'it should receive the expected error message in the `errorHandler`'
@@ -32,14 +36,14 @@ function errorCase(t) {
3236
getState() === 'test',
3337
'it should get the expected state from `getState()`'
3438
);
35-
t.ok(
36-
dispatch === mockedMiddlewareAPI.dispatch,
37-
'dispatch should be passed to the handler'
38-
);
3939
t.ok(
4040
action === errorAction,
4141
'it should pass through the action to the handler'
4242
);
43+
t.ok(
44+
dispatch === mockedMiddlewareAPI.dispatch,
45+
'dispatch should be passed to the handler'
46+
);
4347
}
4448

4549
const error = middleware(errorHandler)(mockedMiddlewareAPI)(mockedNext)(errorAction);
@@ -51,12 +55,14 @@ function errorCase(t) {
5155
}
5256

5357
function successCase(t) {
54-
function mockedNext(action) { return action; }
58+
function mockedNext(action) {
59+
return action;
60+
}
5561

5662
t.plan(1);
5763

5864
const action = middleware(error => error)(mockedMiddlewareAPI)(mockedNext)({
59-
type: 'TEST_ACTION',
65+
type: 'TEST_ACTION'
6066
});
6167

6268
t.equal(

0 commit comments

Comments
 (0)