devour-js / devour-client

Don't just consume your JSON API, Devour it...
https://www.npmjs.com/package/devour-client
ISC License
429 stars 89 forks source link

Example with cancellable requests doesn't work #145

Open x-yuri opened 6 years ago

x-yuri commented 6 years ago

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;
             })
-        })
+        }))
     }
 }