Skip to content

Commit

Permalink
Standardize on Abort over Cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed May 20, 2019
1 parent c689620 commit 3c1de2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions ui/app/adapters/watchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
});
},
Expand All @@ -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) {
Expand All @@ -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(
Expand All @@ -87,7 +87,7 @@ export default ApplicationAdapter.extend({
}

return this.ajax(url, 'GET', {
cancellationToken,
abortToken,
data: params,
}).then(
json => {
Expand Down
6 changes: 3 additions & 3 deletions ui/app/utils/properties/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]);
Expand All @@ -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) {
Expand All @@ -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),
]);
Expand Down
14 changes: 7 additions & 7 deletions ui/tests/unit/adapters/job-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ 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',
'First request is a blocking request for job-1 summary relationship'
);

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',
Expand All @@ -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(() => {});

Expand All @@ -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];
Expand All @@ -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');
Expand All @@ -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];
Expand Down

0 comments on commit 3c1de2d

Please sign in to comment.