New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

axios-hooks

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-hooks - npm Package Compare versions

Comparing version 1.6.0 to 1.7.0

cjs/index.js

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [1.7.0](https://github.com/simoneb/axios-hooks/compare/v1.6.0...v1.7.0) (2019-11-07)
### Features
* support request cancellation ([8cf1f74](https://github.com/simoneb/axios-hooks/commit/8cf1f747c5ae839682f0a6e1da4170e3b1e7b066))
## [1.6.0](https://github.com/simoneb/axios-hooks/compare/v1.5.0...v1.6.0) (2019-10-23)

@@ -7,0 +14,0 @@

202

es/index.js

@@ -0,4 +1,3 @@

import _extends from "@babel/runtime/helpers/esm/extends";
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';

@@ -32,76 +31,58 @@ import DefaultAxios from 'axios';

export function serializeCache() {
return _serializeCache.apply(this, arguments);
}
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));
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 4:
return _context.abrupt("return", cache.dump());
case 4:
return _context.abrupt("return", cache.dump());
case 5:
case "end":
return _context.stop();
}
case 5:
case "end":
return _context.stop();
}
}, _callee);
}));
return _serializeCache.apply(this, arguments);
}
});
}
function cacheAdapter(_x) {
return _cacheAdapter.apply(this, arguments);
}
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() {
_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);
if (!hit) {
_context2.next = 4;
break;
}
if (!hit) {
_context2.next = 4;
break;
}
return _context2.abrupt("return", hit);
return _context2.abrupt("return", hit);
case 4:
delete config.adapter;
_context2.next = 7;
return _regeneratorRuntime.awrap(axiosInstance(config));
case 4:
delete config.adapter;
_context2.next = 7;
return axiosInstance(config);
case 7:
response = _context2.sent;
responseForCache = _extends({}, response);
delete responseForCache.config;
delete responseForCache.request;
cache.set(cacheKey, responseForCache);
return _context2.abrupt("return", response);
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();
}
case 13:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return _cacheAdapter.apply(this, arguments);
}
});
}

@@ -137,48 +118,39 @@

function request(_x2, _x3) {
return _request.apply(this, arguments);
}
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() {
_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 4:
response = _context3.sent;
dispatch({
type: actions.REQUEST_END,
payload: response
});
return _context3.abrupt("return", response);
case 4:
response = _context3.sent;
dispatch({
type: actions.REQUEST_END,
payload: response
});
return _context3.abrupt("return", response);
case 9:
_context3.prev = 9;
_context3.t0 = _context3["catch"](0);
dispatch({
type: actions.REQUEST_END,
payload: _context3.t0,
error: true
});
throw _context3.t0;
case 9:
_context3.prev = 9;
_context3.t0 = _context3["catch"](0);
dispatch({
type: actions.REQUEST_END,
payload: _context3.t0,
error: true
});
throw _context3.t0;
case 13:
case "end":
return _context3.stop();
}
case 13:
case "end":
return _context3.stop();
}
}, _callee3, null, [[0, 9]]);
}));
return _request.apply(this, arguments);
}
}, null, null, [[0, 9]]);
}

@@ -216,2 +188,3 @@

}, options);
var cancelSourceRef = React.useRef();

@@ -229,9 +202,18 @@ var _React$useReducer = React.useReducer(reducer, createInitialState(options)),

React.useEffect(function () {
cancelSourceRef.current = axiosInstance.CancelToken.source();
if (!options.manual) {
executeRequest(config, options, dispatch)["catch"](function () {});
} // eslint-disable-next-line react-hooks/exhaustive-deps
executeRequest(_extends({
cancelToken: cancelSourceRef.current.token
}, config), options, dispatch)["catch"](function () {});
}
return function () {
return cancelSourceRef.current.cancel();
}; // eslint-disable-next-line react-hooks/exhaustive-deps
}, [stringifiedConfig]);
var refetch = React.useCallback(function (configOverride, options) {
return executeRequest(_extends({}, config, {}, configOverride), _extends({
return executeRequest(_extends({
cancelToken: cancelSourceRef.current.token
}, config, {}, configOverride), _extends({
useCache: false

@@ -238,0 +220,0 @@ }, options), dispatch);

{
"name": "axios-hooks",
"version": "1.6.0",
"version": "1.7.0",
"description": "axios-hooks",

@@ -15,16 +15,16 @@ "keywords": [

"bugs": "https://github.com/simoneb/axios-hooks/issues",
"main": "lib/index.js",
"main": "cjs/index.js",
"module": "es/index.js",
"typings": "./index.d.ts",
"files": [
"lib",
"es",
"src",
"index.d.ts"
"cjs/",
"es/",
"src/index.js",
"./index.d.ts"
],
"scripts": {
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src/index.js --out-dir lib",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src/index.js --out-dir cjs",
"build:es": "babel src/index.js --out-dir es",
"build": "run-p build:*",
"clean": "rimraf lib es coverage",
"clean": "rimraf cjs es coverage",
"format": "prettier --write \"src/**/*.{js,md,ts}\"",

@@ -47,12 +47,14 @@ "lint": "eslint src",

"devDependencies": {
"@babel/cli": "7.6.4",
"@babel/core": "7.6.4",
"@babel/cli": "7.7.0",
"@babel/core": "7.7.2",
"@babel/plugin-transform-runtime": "7.6.2",
"@babel/preset-env": "7.6.3",
"@testing-library/react-hooks": "3.1.0",
"@types/jest": "24.0.19",
"@babel/preset-env": "7.7.1",
"@commitlint/cli": "8.2.0",
"@commitlint/config-conventional": "8.2.0",
"@testing-library/react-hooks": "3.2.1",
"@types/jest": "24.0.22",
"@types/lru-cache": "5.1.0",
"@types/node": "12.11.5",
"@types/react": "16.9.9",
"@types/react-dom": "16.9.2",
"@types/node": "12.12.6",
"@types/react": "16.9.11",
"@types/react-dom": "16.9.4",
"axios": "0.19.0",

@@ -62,4 +64,4 @@ "babel-eslint": "10.0.3",

"cz-conventional-changelog": "3.0.2",
"eslint": "6.5.1",
"eslint-config-prettier": "6.4.0",
"eslint": "6.6.0",
"eslint-config-prettier": "6.5.0",
"eslint-plugin-import": "2.18.2",

@@ -79,6 +81,7 @@ "eslint-plugin-prettier": "3.1.1",

"ts-jest": "24.1.0",
"typescript": "3.6.4"
"typescript": "3.7.2"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-commit": "lint-staged",

@@ -85,0 +88,0 @@ "post-merge": "npm i"

@@ -132,2 +132,4 @@ import React from 'react'

const cancelSourceRef = React.useRef()
const [state, dispatch] = React.useReducer(

@@ -143,5 +145,13 @@ reducer,

React.useEffect(() => {
cancelSourceRef.current = axiosInstance.CancelToken.source()
if (!options.manual) {
executeRequest(config, options, dispatch).catch(() => {})
executeRequest(
{ cancelToken: cancelSourceRef.current.token, ...config },
options,
dispatch
).catch(() => {})
}
return () => cancelSourceRef.current.cancel()
// eslint-disable-next-line react-hooks/exhaustive-deps

@@ -153,3 +163,7 @@ }, [stringifiedConfig])

return executeRequest(
{ ...config, ...configOverride },
{
cancelToken: cancelSourceRef.current.token,
...config,
...configOverride
},
{ useCache: false, ...options },

@@ -156,0 +170,0 @@ dispatch

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc