Standardize on Abort over Cancel
This commit is contained in:
parent
c9220cb929
commit
084c4cc95f
|
@ -11,13 +11,13 @@ export default ApplicationAdapter.extend({
|
|||
|
||||
ajaxOptions(url, type, options) {
|
||||
const ajaxOptions = this._super(...arguments);
|
||||
const cancellationToken = (options || {}).cancellationToken;
|
||||
if (cancellationToken) {
|
||||
delete options.cancellationToken;
|
||||
const abortToken = (options || {}).abortToken;
|
||||
if (abortToken) {
|
||||
delete options.abortToken;
|
||||
|
||||
const previousBeforeSend = ajaxOptions.beforeSend;
|
||||
ajaxOptions.beforeSend = function(jqXHR) {
|
||||
cancellationToken.capture(jqXHR);
|
||||
abortToken.capture(jqXHR);
|
||||
if (previousBeforeSend) {
|
||||
previousBeforeSend(...arguments);
|
||||
}
|
||||
|
@ -35,9 +35,9 @@ export default ApplicationAdapter.extend({
|
|||
params.index = this.watchList.getIndexFor(url);
|
||||
}
|
||||
|
||||
const cancellationToken = get(snapshotRecordArray || {}, 'adapterOptions.cancellationToken');
|
||||
const abortToken = get(snapshotRecordArray || {}, 'adapterOptions.abortToken');
|
||||
return this.ajax(url, 'GET', {
|
||||
cancellationToken,
|
||||
abortToken,
|
||||
data: params,
|
||||
});
|
||||
},
|
||||
|
@ -50,9 +50,9 @@ export default ApplicationAdapter.extend({
|
|||
params.index = this.watchList.getIndexFor(url);
|
||||
}
|
||||
|
||||
const cancellationToken = get(snapshot || {}, 'adapterOptions.cancellationToken');
|
||||
const abortToken = get(snapshot || {}, 'adapterOptions.abortToken');
|
||||
return this.ajax(url, 'GET', {
|
||||
cancellationToken,
|
||||
abortToken,
|
||||
data: params,
|
||||
}).catch(error => {
|
||||
if (error instanceof AbortError) {
|
||||
|
@ -62,8 +62,8 @@ export default ApplicationAdapter.extend({
|
|||
});
|
||||
},
|
||||
|
||||
reloadRelationship(model, relationshipName, options = { watch: false, cancellationToken: null }) {
|
||||
const { watch, cancellationToken } = options;
|
||||
reloadRelationship(model, relationshipName, options = { watch: false, abortToken: null }) {
|
||||
const { watch, abortToken } = options;
|
||||
const relationship = model.relationshipFor(relationshipName);
|
||||
if (relationship.kind !== 'belongsTo' && relationship.kind !== 'hasMany') {
|
||||
throw new Error(
|
||||
|
@ -87,7 +87,7 @@ export default ApplicationAdapter.extend({
|
|||
}
|
||||
|
||||
return this.ajax(url, 'GET', {
|
||||
cancellationToken,
|
||||
abortToken,
|
||||
data: params,
|
||||
}).then(
|
||||
json => {
|
||||
|
|
|
@ -19,7 +19,7 @@ export function watchRecord(modelName) {
|
|||
yield RSVP.all([
|
||||
this.store.findRecord(modelName, id, {
|
||||
reload: true,
|
||||
adapterOptions: { watch: true, cancellationToken: token },
|
||||
adapterOptions: { watch: true, abortToken: token },
|
||||
}),
|
||||
wait(throttle),
|
||||
]);
|
||||
|
@ -41,7 +41,7 @@ export function watchRelationship(relationshipName) {
|
|||
yield RSVP.all([
|
||||
this.store
|
||||
.adapterFor(model.constructor.modelName)
|
||||
.reloadRelationship(model, relationshipName, { watch: true, cancellationToken: token }),
|
||||
.reloadRelationship(model, relationshipName, { watch: true, abortToken: token }),
|
||||
wait(throttle),
|
||||
]);
|
||||
} catch (e) {
|
||||
|
@ -62,7 +62,7 @@ export function watchAll(modelName) {
|
|||
yield RSVP.all([
|
||||
this.store.findAll(modelName, {
|
||||
reload: true,
|
||||
adapterOptions: { watch: true, cancellationToken: token },
|
||||
adapterOptions: { watch: true, abortToken: token },
|
||||
}),
|
||||
wait(throttle),
|
||||
]);
|
||||
|
|
|
@ -233,7 +233,7 @@ module('Unit | Adapter | Job', function(hooks) {
|
|||
const plainId = 'job-1';
|
||||
const mockModel = makeMockModel(plainId);
|
||||
|
||||
this.subject().reloadRelationship(mockModel, 'summary', true);
|
||||
this.subject().reloadRelationship(mockModel, 'summary', { watch: true });
|
||||
assert.equal(
|
||||
pretender.handledRequests[0].url,
|
||||
'/v1/job/job-1/summary?index=1',
|
||||
|
@ -241,7 +241,7 @@ module('Unit | Adapter | Job', function(hooks) {
|
|||
);
|
||||
|
||||
await settled();
|
||||
this.subject().reloadRelationship(mockModel, 'summary', true);
|
||||
this.subject().reloadRelationship(mockModel, 'summary', { watch: true });
|
||||
assert.equal(
|
||||
pretender.handledRequests[1].url,
|
||||
'/v1/job/job-1/summary?index=2',
|
||||
|
@ -260,7 +260,7 @@ module('Unit | Adapter | Job', function(hooks) {
|
|||
this.subject()
|
||||
.findAll(null, { modelName: 'job' }, null, {
|
||||
reload: true,
|
||||
adapterOptions: { watch: true, cancellationToken: token },
|
||||
adapterOptions: { watch: true, abortToken: token },
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
|
@ -287,7 +287,7 @@ module('Unit | Adapter | Job', function(hooks) {
|
|||
|
||||
this.subject().findRecord(null, { modelName: 'job' }, jobId, {
|
||||
reload: true,
|
||||
adapterOptions: { watch: true, cancellationToken: token },
|
||||
adapterOptions: { watch: true, abortToken: token },
|
||||
});
|
||||
|
||||
const { request: xhr } = pretender.requestReferences[0];
|
||||
|
@ -311,7 +311,7 @@ module('Unit | Adapter | Job', function(hooks) {
|
|||
const mockModel = makeMockModel(plainId);
|
||||
pretender.get('/v1/job/:id/summary', () => [200, {}, '{}'], true);
|
||||
|
||||
this.subject().reloadRelationship(mockModel, 'summary', true, token);
|
||||
this.subject().reloadRelationship(mockModel, 'summary', { watch: true, abortToken: token });
|
||||
|
||||
const { request: xhr } = pretender.requestReferences[0];
|
||||
assert.equal(xhr.status, 0, 'Request is still pending');
|
||||
|
@ -337,12 +337,12 @@ module('Unit | Adapter | Job', function(hooks) {
|
|||
|
||||
this.subject().findRecord(null, { modelName: 'job' }, jobId, {
|
||||
reload: true,
|
||||
adapterOptions: { watch: true, cancellationToken: token1 },
|
||||
adapterOptions: { watch: true, abortToken: token1 },
|
||||
});
|
||||
|
||||
this.subject().findRecord(null, { modelName: 'job' }, jobId, {
|
||||
reload: true,
|
||||
adapterOptions: { watch: true, cancellationToken: token2 },
|
||||
adapterOptions: { watch: true, abortToken: token2 },
|
||||
});
|
||||
|
||||
const { request: xhr } = pretender.requestReferences[0];
|
||||
|
|
Loading…
Reference in New Issue