[client-app] deprecate returnsModel param for nylas-api-request

Summary:
We no longer need to use the `returnsModel` param since we get all of our
models through the in memory delta stream. There were a ton of places
unnecessarily passing `returnsModel: false` when it defaults to false in
the first place

Depends on D4057

Test Plan: manual

Reviewers: halla, spang, juan

Reviewed By: spang, juan

Differential Revision: https://phab.nylas.com/D4065
This commit is contained in:
Evan Morikawa 2017-03-01 12:13:08 -08:00
parent abaf63202c
commit ba1f429928
15 changed files with 6 additions and 34 deletions

View file

@ -24,7 +24,6 @@ class ContactRankingsCache extends RefreshingJSONCache {
options: {
accountId: this._accountId,
path: "/contacts/rankings",
returnsModel: false,
},
})

View file

@ -136,7 +136,6 @@ export function runAuthRequest(accountInfo) {
timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon
body: data,
auth: noauth,
returnsModel: false,
},
})
return n1CloudIMAPAuthRequest.run().then((remoteJSON) => {
@ -148,7 +147,6 @@ export function runAuthRequest(accountInfo) {
timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon
body: data,
auth: noauth,
returnsModel: false,
},
})
return localSyncIMAPAuthRequest.run().then((localJSON) => {

View file

@ -281,7 +281,6 @@ describe "NylasAPI", ->
expect(this.options.path).toBe "/drafts/#{draft.serverId}"
expect(this.options.accountId).toBe TEST_ACCOUNT_ID
expect(this.options.method).toBe "DELETE"
expect(this.options.returnsModel).toBe false
NylasAPIHelpers.makeDraftDeletionRequest(draft)
it "should increment the change tracker, preventing any further deltas about the draft", ->

View file

@ -120,14 +120,6 @@ xdescribe('SendDraftTask', function sendDraftTask() {
}));
});
it("should pass returnsModel:false", () => {
waitsForPromise(() => this.task.performRemote().then(() => {
expect(NylasAPIRequest.prototype.run.calls.length).toBe(1);
const options = NylasAPIRequest.prototype.run.mostRecentCall.args[0];
expect(options.returnsModel).toBe(false);
}));
});
it("should always send the draft body in the request body (joined attribute check)", () => {
waitsForPromise(() => this.task.performRemote().then(() => {
expect(NylasAPIRequest.prototype.run.calls.length).toBe(1);

View file

@ -183,15 +183,6 @@ xdescribe('SyncbackDraftTask', function syncbackDraftTask() {
}));
});
it("should pass returnsModel:false so that the draft can be manually removed/added to the database, accounting for its ID change", () => {
const task = new SyncbackDraftTask("localDraftId");
waitsForPromise(() => task.performRemote().then(() => {
expect(NylasAPIRequest.prototype.run).toHaveBeenCalled();
const options = NylasAPIRequest.prototype.run.mostRecentCall.args[0];
expect(options.returnsModel).toBe(false);
}));
});
it("should save metadata associated with the draft when the draft has been already saved to the api", () => {
const draft = remoteDraft();
draft.pluginMetadata = [{pluginId: 1, value: {a: 1}}];

View file

@ -147,7 +147,6 @@ xdescribe('SyncbackModelTask', function syncbackModelTask() {
expect(opts.path).toBe("/test")
expect(opts.method).toBe("POST")
expect(opts.accountId).toBe("account-123")
expect(opts.returnsModel).toBe(false)
expect(opts.body).toEqual(this.testModel.toJSON())
});
});

View file

@ -2,6 +2,7 @@ import Actions from './actions'
import {APIError} from './errors'
import DatabaseStore from './stores/database-store'
import NylasAPIRequest from './nylas-api-request'
import NylasAPIHelpers from './nylas-api-helpers'
import ProviderSyncbackRequest from './models/provider-syncback-request'
/**
@ -61,7 +62,6 @@ class SyncbackTaskAPIRequest {
}
constructor({api, options}) {
options.returnsModel = true
this._request = new NylasAPIRequest({api, options})
this._onSyncbackRequestCreated = options.onSyncbackRequestCreated || (() => {})
}
@ -69,12 +69,16 @@ class SyncbackTaskAPIRequest {
run() {
return new Promise(async (resolve, reject) => {
try {
const syncbackRequest = await this._request.run()
const syncbackRequest = await this._request.run();
await NylasAPIHelpers.handleModelResponse(syncbackRequest)
await this._onSyncbackRequestCreated(syncbackRequest)
const syncbackRequestId = syncbackRequest.id
SyncbackTaskAPIRequest.listenForRequest(syncbackRequestId)
.then(resolve).catch(reject)
} catch (err) {
if (err.response && err.response.statusCode === 404) {
NylasAPIHelpers.handleModel404(this._request.options.url)
}
reject(err)
}
})

View file

@ -231,7 +231,6 @@ export default class ChangeMailTask extends Task {
accountId: model.accountId,
method: 'PUT',
body: this.requestBodyForModel(model),
returnsModel: true,
onSyncbackRequestCreated: (syncbackRequest) => {
if (!this._syncbackRequestIds) this._syncbackRequestIds = {}
this._syncbackRequestIds[model.id] = syncbackRequest.id

View file

@ -64,7 +64,6 @@ export default class DestroyCategoryTask extends Task {
accountId,
path,
method: 'DELETE',
returnsModel: false,
onSyncbackRequestCreated: (syncbackRequest) => {
this._syncbackRequestId = syncbackRequest.id
},

View file

@ -45,7 +45,6 @@ export default class DestroyDraftTask extends BaseDraftTask {
body: {
version: this.draft.version,
},
returnsModel: false,
},
})
.run()

View file

@ -46,7 +46,6 @@ export default class EventRSVPTask extends Task {
event_id: id,
status: this.RSVPResponse,
},
returnsModel: true,
},
})
.run()

View file

@ -67,9 +67,6 @@ export default class SyncbackCategoryTask extends Task {
body: {
display_name: this.displayName || this.category.displayName,
},
// returnsModel must be false because we want to update the
// existing model rather than returning a new model.
returnsModel: false,
onSyncbackRequestCreated: (syncbackRequest) => {
this._syncbackRequestId = syncbackRequest.id
},

View file

@ -21,7 +21,6 @@ export default class SyncbackDraftTask extends BaseDraftTask {
path: (this.draft.serverId) ? `/drafts/${this.draft.serverId}` : "/drafts",
method: (this.draft.serverId) ? 'PUT' : 'POST',
body: this.draft.toJSON(),
returnsModel: false,
},
})
.run()

View file

@ -29,7 +29,6 @@ export default class SyncbackMetadataTask extends SyncbackModelTask {
}
const options = {
accountId: model.accountId,
returnsModel: false,
path: `/metadata/${model.serverId}/${this.pluginId}`,
method: 'POST',
body: {

View file

@ -53,7 +53,6 @@ export default class SyncbackModelTask extends Task {
try {
const options = _.extend({
accountId: model.accountId,
returnsModel: false,
}, this.getRequestData(model));
return new NylasAPIRequest({
api: NylasAPI,