Comparing version
@@ -33,19 +33,25 @@ 'use strict'; | ||
function isAgent(obj) { | ||
return obj && typeof obj.get === 'function' && typeof obj.post === 'function' && typeof obj.del === 'function' && typeof obj.put === 'function'; | ||
} | ||
exports.default = function () { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
client = _ref.client, | ||
_ref$endEvents = _ref.endEvents, | ||
endEvents = _ref$endEvents === undefined ? ['end', 'abort', 'error'] : _ref$endEvents, | ||
_ref$methods = _ref.methods, | ||
methods = _ref$methods === undefined ? ['get', 'post', 'del', 'put'] : _ref$methods, | ||
_ref$abortKey = _ref.abortKey, | ||
abortKey = _ref$abortKey === undefined ? 'abort' : _ref$abortKey, | ||
_ref$pendingKey = _ref.pendingKey, | ||
pendingKey = _ref$pendingKey === undefined ? 'pending' : _ref$pendingKey; | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return function (OriginalComponent) { | ||
if (!OriginalComponent) throw new Error('No component to wrap.'); | ||
var _ref = isAgent(opts) ? { client: opts } : opts, | ||
client = _ref.client, | ||
_ref$endEvents = _ref.endEvents, | ||
endEvents = _ref$endEvents === undefined ? ['end', 'abort', 'error'] : _ref$endEvents, | ||
_ref$methods = _ref.methods, | ||
methods = _ref$methods === undefined ? ['get', 'post', 'del', 'put'] : _ref$methods, | ||
_ref$abortKey = _ref.abortKey, | ||
abortKey = _ref$abortKey === undefined ? 'abort' : _ref$abortKey, | ||
_ref$pendingKey = _ref.pendingKey, | ||
pendingKey = _ref$pendingKey === undefined ? 'pending' : _ref$pendingKey; | ||
// return a higher-order-component | ||
var WrappedComponent = function (_Component) { | ||
@@ -52,0 +58,0 @@ _inherits(WrappedComponent, _Component); |
{ | ||
"name": "react-jax", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A tiny decorator to manage AJAX requests in React components.", | ||
@@ -51,3 +51,2 @@ "main": "lib/index.js", | ||
"react": "^15.6.1", | ||
"react-addons-test-utils": "^15.6.0", | ||
"react-dom": "^15.6.1", | ||
@@ -54,0 +53,0 @@ "sinon": "^1.17.5", |
@@ -17,8 +17,3 @@ # react-jax [](https://travis-ci.org/azuqua/react-jax) | ||
@jax({ | ||
client: superagent, // only required option | ||
methods: ['get', 'post', 'del', 'put'], | ||
pendingKey: 'pending', | ||
abortKey: 'abort' | ||
}) | ||
@jax(superagent) | ||
export default class MyComponent extends React.Component { | ||
@@ -61,4 +56,7 @@ | ||
These options are passed to the `jax()` function. | ||
You can choose to pass a superagent client or an object | ||
for additional options. | ||
These options can be passed to the `jax()` decorator. | ||
##### `client` __required__ | ||
@@ -65,0 +63,0 @@ |
13021
1.42%18
-5.26%133
3.1%86
-2.27%