axios-hooks
Advanced tools
Comparing version 1.9.0 to 1.10.0-0
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.10.0-0](https://github.com/simoneb/axios-hooks/compare/v1.9.0...v1.10.0-0) (2020-04-11) | ||
### Features | ||
* **199:** add ability to disable cache ([b8f504a](https://github.com/simoneb/axios-hooks/commit/b8f504a1e85f415d70f17d1d38b6c17b33a1372f)), closes [#199](https://github.com/simoneb/axios-hooks/issues/199) | ||
## [1.9.0](https://github.com/simoneb/axios-hooks/compare/v1.8.0...v1.9.0) (2019-12-12) | ||
@@ -7,0 +14,0 @@ |
206
cjs/index.js
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -9,6 +9,8 @@ exports.__esModule = true; | ||
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends.js")); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _index = _interopRequireDefault(require("@babel/runtime/regenerator/index.js")); | ||
var _extends3 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _react = _interopRequireDefault(require("react")); | ||
@@ -48,4 +50,2 @@ | ||
resetConfigure(); | ||
function configure(options) { | ||
@@ -56,7 +56,7 @@ if (options === void 0) { | ||
if (options.axios) { | ||
if (options.axios !== undefined) { | ||
axiosInstance = options.axios; | ||
} | ||
if (options.cache) { | ||
if (options.cache !== undefined) { | ||
cache = options.cache; | ||
@@ -66,2 +66,3 @@ } | ||
resetConfigure(); | ||
configure(configurationOptions); | ||
@@ -74,21 +75,28 @@ | ||
function serializeCache() { | ||
var ssrPromisesCopy; | ||
return _index["default"].async(function serializeCache$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
ssrPromisesCopy = [].concat(__ssrPromises); | ||
__ssrPromises.length = 0; | ||
_context.next = 4; | ||
return _index["default"].awrap(Promise.all(ssrPromisesCopy)); | ||
return _serializeCache.apply(this, arguments); | ||
} | ||
case 4: | ||
return _context.abrupt("return", cache.dump()); | ||
function _serializeCache() { | ||
_serializeCache = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var ssrPromisesCopy; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
ssrPromisesCopy = [].concat(__ssrPromises); | ||
__ssrPromises.length = 0; | ||
_context.next = 4; | ||
return Promise.all(ssrPromisesCopy); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
case 4: | ||
return _context.abrupt("return", cache.dump()); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}); | ||
}, _callee); | ||
})); | ||
return _serializeCache.apply(this, arguments); | ||
} | ||
@@ -104,37 +112,44 @@ | ||
function cacheAdapter(config) { | ||
var cacheKey, hit, response, responseForCache; | ||
return _index["default"].async(function cacheAdapter$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cacheKey = JSON.stringify(config); | ||
hit = cache.get(cacheKey); | ||
function cacheAdapter(_x) { | ||
return _cacheAdapter.apply(this, arguments); | ||
} | ||
if (!hit) { | ||
_context2.next = 4; | ||
break; | ||
} | ||
function _cacheAdapter() { | ||
_cacheAdapter = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(config) { | ||
var cacheKey, hit, response, responseForCache; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cacheKey = JSON.stringify(config); | ||
hit = cache.get(cacheKey); | ||
return _context2.abrupt("return", hit); | ||
if (!hit) { | ||
_context2.next = 4; | ||
break; | ||
} | ||
case 4: | ||
delete config.adapter; | ||
_context2.next = 7; | ||
return _index["default"].awrap(axiosInstance(config)); | ||
return _context2.abrupt("return", hit); | ||
case 7: | ||
response = _context2.sent; | ||
responseForCache = (0, _extends3["default"])({}, response); | ||
delete responseForCache.config; | ||
delete responseForCache.request; | ||
cache.set(cacheKey, responseForCache); | ||
return _context2.abrupt("return", response); | ||
case 4: | ||
delete config.adapter; | ||
_context2.next = 7; | ||
return axiosInstance(config); | ||
case 13: | ||
case "end": | ||
return _context2.stop(); | ||
case 7: | ||
response = _context2.sent; | ||
responseForCache = (0, _extends3["default"])({}, response); | ||
delete responseForCache.config; | ||
delete responseForCache.request; | ||
cache.set(cacheKey, responseForCache); | ||
return _context2.abrupt("return", response); | ||
case 13: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
} | ||
}); | ||
}, _callee2); | ||
})); | ||
return _cacheAdapter.apply(this, arguments); | ||
} | ||
@@ -170,48 +185,55 @@ | ||
function request(config, dispatch) { | ||
var response; | ||
return _index["default"].async(function request$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.prev = 0; | ||
dispatch({ | ||
type: actions.REQUEST_START | ||
}); | ||
_context3.next = 4; | ||
return _index["default"].awrap(axiosInstance(config)); | ||
function request(_x2, _x3) { | ||
return _request.apply(this, arguments); | ||
} | ||
case 4: | ||
response = _context3.sent; | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: response | ||
}); | ||
return _context3.abrupt("return", response); | ||
function _request() { | ||
_request = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(config, dispatch) { | ||
var response; | ||
return _regenerator["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.prev = 0; | ||
dispatch({ | ||
type: actions.REQUEST_START | ||
}); | ||
_context3.next = 4; | ||
return axiosInstance(config); | ||
case 9: | ||
_context3.prev = 9; | ||
_context3.t0 = _context3["catch"](0); | ||
case 4: | ||
response = _context3.sent; | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: response | ||
}); | ||
return _context3.abrupt("return", response); | ||
if (!_axios["default"].isCancel(_context3.t0)) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
case 9: | ||
_context3.prev = 9; | ||
_context3.t0 = _context3["catch"](0); | ||
return _context3.abrupt("return"); | ||
if (!_axios["default"].isCancel(_context3.t0)) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
case 13: | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: _context3.t0, | ||
error: true | ||
}); | ||
throw _context3.t0; | ||
return _context3.abrupt("return"); | ||
case 15: | ||
case "end": | ||
return _context3.stop(); | ||
case 13: | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: _context3.t0, | ||
error: true | ||
}); | ||
throw _context3.t0; | ||
case 15: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
} | ||
}, null, null, [[0, 9]]); | ||
}, _callee3, null, [[0, 9]]); | ||
})); | ||
return _request.apply(this, arguments); | ||
} | ||
@@ -230,3 +252,3 @@ | ||
function executeRequest(config, options, dispatch) { | ||
if (options.useCache) { | ||
if (cache && options.useCache) { | ||
return executeRequestWithCache(config, dispatch); | ||
@@ -233,0 +255,0 @@ } |
203
es/index.js
@@ -1,3 +0,4 @@ | ||
import _extends from "@babel/runtime/helpers/esm/extends.js"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator/index.js"; | ||
import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
import _extends from "@babel/runtime/helpers/esm/extends"; | ||
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; | ||
import React from 'react'; | ||
@@ -28,4 +29,2 @@ import StaticAxios from 'axios'; | ||
resetConfigure(); | ||
function configure(options) { | ||
@@ -36,7 +35,7 @@ if (options === void 0) { | ||
if (options.axios) { | ||
if (options.axios !== undefined) { | ||
axiosInstance = options.axios; | ||
} | ||
if (options.cache) { | ||
if (options.cache !== undefined) { | ||
cache = options.cache; | ||
@@ -46,2 +45,3 @@ } | ||
resetConfigure(); | ||
configure(configurationOptions); | ||
@@ -54,21 +54,28 @@ | ||
function serializeCache() { | ||
var ssrPromisesCopy; | ||
return _regeneratorRuntime.async(function serializeCache$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
ssrPromisesCopy = [].concat(__ssrPromises); | ||
__ssrPromises.length = 0; | ||
_context.next = 4; | ||
return _regeneratorRuntime.awrap(Promise.all(ssrPromisesCopy)); | ||
return _serializeCache.apply(this, arguments); | ||
} | ||
case 4: | ||
return _context.abrupt("return", cache.dump()); | ||
function _serializeCache() { | ||
_serializeCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
var ssrPromisesCopy; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
ssrPromisesCopy = [].concat(__ssrPromises); | ||
__ssrPromises.length = 0; | ||
_context.next = 4; | ||
return Promise.all(ssrPromisesCopy); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
case 4: | ||
return _context.abrupt("return", cache.dump()); | ||
case 5: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
} | ||
}); | ||
}, _callee); | ||
})); | ||
return _serializeCache.apply(this, arguments); | ||
} | ||
@@ -84,37 +91,44 @@ | ||
function cacheAdapter(config) { | ||
var cacheKey, hit, response, responseForCache; | ||
return _regeneratorRuntime.async(function cacheAdapter$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cacheKey = JSON.stringify(config); | ||
hit = cache.get(cacheKey); | ||
function cacheAdapter(_x) { | ||
return _cacheAdapter.apply(this, arguments); | ||
} | ||
if (!hit) { | ||
_context2.next = 4; | ||
break; | ||
} | ||
function _cacheAdapter() { | ||
_cacheAdapter = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(config) { | ||
var cacheKey, hit, response, responseForCache; | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
cacheKey = JSON.stringify(config); | ||
hit = cache.get(cacheKey); | ||
return _context2.abrupt("return", hit); | ||
if (!hit) { | ||
_context2.next = 4; | ||
break; | ||
} | ||
case 4: | ||
delete config.adapter; | ||
_context2.next = 7; | ||
return _regeneratorRuntime.awrap(axiosInstance(config)); | ||
return _context2.abrupt("return", hit); | ||
case 7: | ||
response = _context2.sent; | ||
responseForCache = _extends({}, response); | ||
delete responseForCache.config; | ||
delete responseForCache.request; | ||
cache.set(cacheKey, responseForCache); | ||
return _context2.abrupt("return", response); | ||
case 4: | ||
delete config.adapter; | ||
_context2.next = 7; | ||
return axiosInstance(config); | ||
case 13: | ||
case "end": | ||
return _context2.stop(); | ||
case 7: | ||
response = _context2.sent; | ||
responseForCache = _extends({}, response); | ||
delete responseForCache.config; | ||
delete responseForCache.request; | ||
cache.set(cacheKey, responseForCache); | ||
return _context2.abrupt("return", response); | ||
case 13: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
} | ||
}); | ||
}, _callee2); | ||
})); | ||
return _cacheAdapter.apply(this, arguments); | ||
} | ||
@@ -150,48 +164,55 @@ | ||
function request(config, dispatch) { | ||
var response; | ||
return _regeneratorRuntime.async(function request$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.prev = 0; | ||
dispatch({ | ||
type: actions.REQUEST_START | ||
}); | ||
_context3.next = 4; | ||
return _regeneratorRuntime.awrap(axiosInstance(config)); | ||
function request(_x2, _x3) { | ||
return _request.apply(this, arguments); | ||
} | ||
case 4: | ||
response = _context3.sent; | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: response | ||
}); | ||
return _context3.abrupt("return", response); | ||
function _request() { | ||
_request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(config, dispatch) { | ||
var response; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.prev = 0; | ||
dispatch({ | ||
type: actions.REQUEST_START | ||
}); | ||
_context3.next = 4; | ||
return axiosInstance(config); | ||
case 9: | ||
_context3.prev = 9; | ||
_context3.t0 = _context3["catch"](0); | ||
case 4: | ||
response = _context3.sent; | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: response | ||
}); | ||
return _context3.abrupt("return", response); | ||
if (!StaticAxios.isCancel(_context3.t0)) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
case 9: | ||
_context3.prev = 9; | ||
_context3.t0 = _context3["catch"](0); | ||
return _context3.abrupt("return"); | ||
if (!StaticAxios.isCancel(_context3.t0)) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
case 13: | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: _context3.t0, | ||
error: true | ||
}); | ||
throw _context3.t0; | ||
return _context3.abrupt("return"); | ||
case 15: | ||
case "end": | ||
return _context3.stop(); | ||
case 13: | ||
dispatch({ | ||
type: actions.REQUEST_END, | ||
payload: _context3.t0, | ||
error: true | ||
}); | ||
throw _context3.t0; | ||
case 15: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
} | ||
}, null, null, [[0, 9]]); | ||
}, _callee3, null, [[0, 9]]); | ||
})); | ||
return _request.apply(this, arguments); | ||
} | ||
@@ -210,3 +231,3 @@ | ||
function executeRequest(config, options, dispatch) { | ||
if (options.useCache) { | ||
if (cache && options.useCache) { | ||
return executeRequestWithCache(config, dispatch); | ||
@@ -213,0 +234,0 @@ } |
{ | ||
"name": "axios-hooks", | ||
"version": "1.9.0", | ||
"version": "1.10.0-0", | ||
"description": "axios-hooks", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@babel/runtime": "7.7.6", | ||
"@babel/runtime": "7.9.2", | ||
"lru-cache": "5.1.1" | ||
@@ -47,37 +47,37 @@ }, | ||
"devDependencies": { | ||
"@babel/cli": "7.7.5", | ||
"@babel/core": "7.7.5", | ||
"@babel/plugin-transform-runtime": "7.7.6", | ||
"@babel/preset-env": "7.7.6", | ||
"@babel/preset-react": "7.7.4", | ||
"@commitlint/cli": "8.2.0", | ||
"@commitlint/config-conventional": "8.2.0", | ||
"@babel/cli": "7.8.4", | ||
"@babel/core": "7.9.0", | ||
"@babel/plugin-transform-runtime": "7.9.0", | ||
"@babel/preset-env": "7.9.0", | ||
"@babel/preset-react": "7.9.4", | ||
"@commitlint/cli": "8.3.5", | ||
"@commitlint/config-conventional": "8.3.4", | ||
"@testing-library/react-hooks": "3.2.1", | ||
"@types/jest": "24.0.23", | ||
"@types/jest": "25.2.1", | ||
"@types/lru-cache": "5.1.0", | ||
"@types/node": "12.12.17", | ||
"@types/react": "16.9.16", | ||
"@types/react-dom": "16.9.4", | ||
"axios": "0.19.0", | ||
"babel-eslint": "10.0.3", | ||
"cross-env": "6.0.3", | ||
"cz-conventional-changelog": "3.0.2", | ||
"eslint": "6.7.2", | ||
"eslint-config-prettier": "6.7.0", | ||
"eslint-plugin-import": "2.19.1", | ||
"eslint-plugin-prettier": "3.1.1", | ||
"eslint-plugin-react": "7.16.0", | ||
"eslint-plugin-react-hooks": "2.3.0", | ||
"husky": "3.1.0", | ||
"jest": "24.9.0", | ||
"lint-staged": "9.5.0", | ||
"@types/node": "12.12.24", | ||
"@types/react": "16.9.23", | ||
"@types/react-dom": "16.9.6", | ||
"axios": "0.19.2", | ||
"babel-eslint": "10.1.0", | ||
"cross-env": "7.0.2", | ||
"cz-conventional-changelog": "3.1.0", | ||
"eslint": "6.8.0", | ||
"eslint-config-prettier": "6.10.1", | ||
"eslint-plugin-import": "2.20.2", | ||
"eslint-plugin-prettier": "3.1.2", | ||
"eslint-plugin-react": "7.19.0", | ||
"eslint-plugin-react-hooks": "3.0.0", | ||
"husky": "4.2.3", | ||
"jest": "25.1.0", | ||
"lint-staged": "10.0.8", | ||
"npm-run-all": "4.1.5", | ||
"prettier": "1.19.1", | ||
"react": "16.12.0", | ||
"react-dom": "16.12.0", | ||
"react-test-renderer": "16.12.0", | ||
"rimraf": "3.0.0", | ||
"standard-version": "7.0.1", | ||
"ts-jest": "24.2.0", | ||
"typescript": "3.7.3" | ||
"prettier": "2.0.2", | ||
"react": "16.13.1", | ||
"react-dom": "16.13.1", | ||
"react-test-renderer": "16.13.1", | ||
"rimraf": "3.0.2", | ||
"standard-version": "7.1.0", | ||
"ts-jest": "25.3.1", | ||
"typescript": "3.8.3" | ||
}, | ||
@@ -93,4 +93,3 @@ "husky": { | ||
"src/**/*.{js,md}": [ | ||
"prettier --write", | ||
"git add" | ||
"eslint --fix" | ||
] | ||
@@ -97,0 +96,0 @@ }, |
@@ -84,3 +84,3 @@ # axios-hooks | ||
- `loading` - True if the request is in progress, otherwise False. | ||
- `error` - The [error](https://github.com/axios/.axios#handling-errors) value | ||
- `error` - The [error](https://github.com/axios/axios#handling-errors) value | ||
- `response` - The whole [success response](https://github.com/axios/axios#response-schema) object. | ||
@@ -97,3 +97,3 @@ | ||
- `cache` An instance of [lru-cache](https://github.com/isaacs/node-lru-cache) | ||
- `cache` An instance of [lru-cache](https://github.com/isaacs/node-lru-cache), or `false` to disable the cache | ||
- `axios` An instance of [axios](https://github.com/axios/axios#creating-an-instance) | ||
@@ -119,3 +119,3 @@ | ||
- `cache` An instance of [lru-cache](https://github.com/isaacs/node-lru-cache) | ||
- `cache` An instance of [lru-cache](https://github.com/isaacs/node-lru-cache), or `false` to disable the cache | ||
- `axios` An instance of [axios](https://github.com/axios/axios#creating-an-instance) | ||
@@ -143,6 +143,7 @@ | ||
These defaults may not suit your needs: | ||
These defaults may not suit your needs, for example: | ||
- you may want a common base url for axios requests | ||
- the default (Infinite) cache size may not be a sensible default | ||
- you want to disable caching altogether | ||
@@ -149,0 +150,0 @@ In such cases you can use the `configure` function to provide your custom implementation of both. |
@@ -29,3 +29,3 @@ import { | ||
axios?: AxiosInstance | AxiosStatic | any | ||
cache?: LRUCache<any, any> | ||
cache?: LRUCache<any, any> | false | ||
} | ||
@@ -32,0 +32,0 @@ |
@@ -35,10 +35,8 @@ import React from 'react' | ||
resetConfigure() | ||
function configure(options = {}) { | ||
if (options.axios) { | ||
if (options.axios !== undefined) { | ||
axiosInstance = options.axios | ||
} | ||
if (options.cache) { | ||
if (options.cache !== undefined) { | ||
cache = options.cache | ||
@@ -48,2 +46,3 @@ } | ||
resetConfigure() | ||
configure(configurationOptions) | ||
@@ -145,3 +144,3 @@ | ||
function executeRequest(config, options, dispatch) { | ||
if (options.useCache) { | ||
if (cache && options.useCache) { | ||
return executeRequestWithCache(config, dispatch) | ||
@@ -148,0 +147,0 @@ } |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
43098
692
328
1
+ Added@babel/runtime@7.9.2(transitive)
- Removed@babel/runtime@7.7.6(transitive)
Updated@babel/runtime@7.9.2