Example with cancellable requests doesn't work
Opened this issue · 0 comments
x-yuri commented
The part of the README on cancellable requests says:
let cancellableRequest = {
name: 'axios-cancellable-request',
req: function (payload) {
let jsonApi = payload.jsonApi
return jsonApi.axios(payload.req, {
cancelToken: new jsonApi.axios.CancelToken(function executor(c) {
// An executor function receives a cancel function as a parameter
jsonApi.cancel = c;
})
})
}
}
But it doesn't work this way. And I can't see axios
taking two params:
index.js -> require('./lib/axios')
lib/axios/index.js -> var axios = createInstance(...)
lib/axios/index.js: createInstance -> var instance = bind(Axios.prototype.request, ...);
lib/axios/index.js -> module.exports = axios
Axios.prototype.request
So, the code is supposed to read:
--- 1.js 2018-07-06 14:12:14.831122597 +0300
+++ 2.js 2018-07-06 14:12:33.521123021 +0300
@@ -2,11 +2,11 @@
name: 'axios-cancellable-request',
req: function (payload) {
let jsonApi = payload.jsonApi
- return jsonApi.axios(payload.req, {
+ return jsonApi.axios(Object.assign(payload.req, {
cancelToken: new jsonApi.axios.CancelToken(function executor(c) {
// An executor function receives a cancel function as a parameter
jsonApi.cancel = c;
})
- })
+ }))
}
}