Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "redux-req", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A redux middleware for handling HTTP requests", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -6,3 +6,3 @@ # redux-request | ||
[](https://travis-ci.org/jedirandy/redux-request) | ||
[](https://travis-ci.org/jedirandy/redux-req) | ||
[](https://david-dm.org/jedirandy/redux-req) | ||
@@ -47,4 +47,5 @@ [](https://www.npmjs.org/package/redux-req) | ||
| payload | any | the request payload | | ||
| beforeSend | function | a function passed with the XHR object, so that some extra work can be done before sending the request | | ||
## License | ||
MIT |
@@ -12,3 +12,4 @@ import request from './request'; | ||
receiveType, | ||
resourceName | ||
resourceName, | ||
beforeSend | ||
} = action; | ||
@@ -23,2 +24,3 @@ let requestedAt = new Date(); | ||
payload, | ||
beforeSend, | ||
onSuccess: res => next({ | ||
@@ -25,0 +27,0 @@ type: receiveType, |
@@ -0,8 +1,12 @@ | ||
const noop = () => {}; | ||
export const request = (url, method, { | ||
payload, | ||
onSuccess, | ||
onError | ||
onError, | ||
beforeSend = noop | ||
}) => { | ||
let xhr = new XMLHttpRequest(); | ||
xhr.open(method, url, true); | ||
beforeSend(xhr); | ||
xhr.send(payload); | ||
@@ -9,0 +13,0 @@ xhr.onreadystatechange = () => { |
11355
235
50