-
-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Closed
Description
So, if I understand it right, in 0.19.0 you've added mergeConfig
And this function filter config and remove custom properties from it.
It broke my solution for cancellation:
How it works:
const requestManager = new RequestManager();
const instance = axios.create();
requestManager.patchAxiosInstance(instance);
const search = q =>
instance.get('/search', {
cancelable: true, // this is no longer possible in 0.19.0
params: { q },
});The solution:
class RequestManager {
constructor() {
this.pendingRequests = new Map();
}
patchAxiosInstance(instance) {
instance.interceptors.request.use(config => {
if (!config.cancelable) return config; // this is no longer possible in 0.19.0
const source = axios.CancelToken.source();
const requestId = `${config.method}_${config.url}`;
const cancelToken = source.token;
this.addRequest(requestId, source.cancel);
return { ...config, cancelToken, requestId };
});
instance.interceptors.response.use(response => {
const { requestId } = response.config; // this is no longer possible in 0.19.0
if (requestId) {
this.removeRequest(requestId);
}
return response;
});
}
addRequest(requestId, cancelFn) {
this.cancelRequest(requestId);
this.pendingRequests.set(requestId, cancelFn);
}
removeRequest(requestId) {
this.pendingRequests.delete(requestId);
}
cancelRequest(requestId) {
if (this.pendingRequests.has(requestId)) {
const cancelFn = this.pendingRequests.get(requestId);
cancelFn();
this.removeRequest(requestId);
}
}
}So, is it possible to relax filter in mergeConfig for custom properties? Because sometimes it is needed and very helpful in interceptors or somewhere else.
SleepWalker, mattjennings, Kamahl19, amoshydra, jkourou and 36 moremishokupatadze
Metadata
Metadata
Assignees
Labels
No labels
