Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with cancellable requests doesn't work #145

Open
x-yuri opened this issue Jul 6, 2018 · 0 comments
Open

Example with cancellable requests doesn't work #145

x-yuri opened this issue Jul 6, 2018 · 0 comments

Comments

@x-yuri
Copy link

x-yuri commented Jul 6, 2018

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;
             })
-        })
+        }))
     }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant