Never duplicate query params, always include query params

A couple more edge cases related to watching URLs with query params
This commit is contained in:
Michael Lange 2018-03-22 18:58:45 -07:00
parent ca98d6b0c8
commit 1413ed1a44

View file

@ -54,7 +54,6 @@ export default ApplicationAdapter.extend({
if (get(snapshot || {}, 'adapterOptions.watch')) {
params.index = this.get('watchList').getIndexFor(url);
this.cancelFindRecord(type.modelName, id);
}
return this.ajax(url, 'GET', {
@ -79,11 +78,15 @@ export default ApplicationAdapter.extend({
if (watch) {
params.index = this.get('watchList').getIndexFor(url);
this.cancelReloadRelationship(model, relationshipName);
}
// Avoid duplicating existing query params by passing them to ajax
// in the URL and in options.data
if (url.includes('?')) {
params = assign(queryString.parse(url.split('?')[1]), params);
const paramsInUrl = queryString.parse(url.split('?')[1]);
Object.keys(paramsInUrl).forEach(key => {
delete params[key];
});
}
return this.ajax(url, 'GET', {
@ -134,7 +137,12 @@ export default ApplicationAdapter.extend({
if (!modelName) {
return;
}
const xhr = this.get('xhrs')[this.urlForFindAll(modelName)];
let url = this.urlForFindAll(modelName);
const params = queryString.stringify(this.buildQuery());
if (params) {
url = `${url}?${params}`;
}
const xhr = this.get('xhrs')[url];
if (xhr) {
xhr.abort();
}