Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit b4d3da1

Browse files
committed
[client-app] (deltas P3) Change onResults interface in NylasLongConnection
Summary: For legacy reasons, NylasLongConnection did not take the `onResults` callback as an option, but rather it was a method you had to call on the connection, which took the callback, and which you had to call after instantiating the connection. This was an annoying and clunky interface. This commit makes it so NylasLongConnection takes an `onResults` option as one would expect it to, and updates any references to the old interface Depends on D4118 Test Plan: manual Reviewers: halla, mark, spang, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D4119
1 parent 92bf048 commit b4d3da1

File tree

4 files changed

+22
-26
lines changed

4 files changed

+22
-26
lines changed

packages/client-app/internal_packages/deltas/lib/delta-streaming-connection.es6

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@ import {NylasLongConnection, DatabaseStore} from 'nylas-exports'
33

44
class DeltaStreamingConnection extends NylasLongConnection {
55
constructor(api, accountId, opts = {}) {
6+
// TODO FYI this whole class is changing in an upcoming diff
7+
opts.api = api
8+
opts.accountId = accountId
69
opts.throttleResultsInterval = 1000
710
opts.closeIfDataStopsInterval = 15 * 1000
8-
super(api, accountId, opts)
9-
10-
this._onError = opts.onError || (() => {})
11-
12-
const {getCursor, setCursor} = opts
13-
this._getCursor = getCursor
14-
this._setCursor = setCursor
1511

1612
// Update cursor when deltas received
17-
this.onResults((deltas = []) => {
13+
opts.onResuls = (deltas = []) => {
1814
if (opts.onDeltas) opts.onDeltas(deltas, {source: "n1Cloud"});
1915
const last = _.last(deltas);
2016
if (last && last.cursor) {
2117
this._setCursor(last.cursor)
2218
}
23-
})
19+
}
20+
super(opts)
21+
22+
this._onError = opts.onError || (() => {})
23+
24+
const {getCursor, setCursor} = opts
25+
this._getCursor = getCursor
26+
this._setCursor = setCursor
2427
}
2528

2629
_deltaStreamingPath(cursor) {

packages/client-app/internal_packages/thread-search/lib/search-query-subscription.es6

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {
44
NylasAPI,
55
Thread,
66
DatabaseStore,
7+
SearchQueryParser,
78
ComponentRegistry,
9+
NylasLongConnection,
810
FocusedContentStore,
911
MutableQuerySubscription,
10-
SearchQueryParser,
1112
} from 'nylas-exports'
1213
import SearchActions from './search-actions'
1314

@@ -113,8 +114,9 @@ class SearchQuerySubscription extends MutableQuerySubscription {
113114
}
114115

115116
this._connections = this._accountIds.map((accountId) => {
116-
return NylasAPI.startLongConnection({
117+
const conn = new NylasLongConnection({
117118
accountId,
119+
api: NylasAPI,
118120
path: `/threads/search/streaming?q=${encodeURIComponent(this._searchQuery)}`,
119121
onResults: (results) => {
120122
if (!this._remoteResultsReceivedAt) {
@@ -139,6 +141,8 @@ class SearchQuerySubscription extends MutableQuerySubscription {
139141
}
140142
},
141143
})
144+
145+
return conn.start()
142146
})
143147
}
144148

packages/client-app/src/flux/nylas-api.es6

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ class NylasAPI {
5959
return AccountStore.tokensForAccountId(aid).localSync
6060
}
6161

62-
longConnection = (opts) => {
63-
const connection = new NylasLongConnection(this, opts.accountId, opts)
64-
connection.onResults(opts.onResults)
65-
return connection
66-
}
67-
68-
startLongConnection = (opts) => {
69-
return this.longConnection(opts).start()
70-
}
71-
7262
incrementRemoteChangeLock = (klass, id) => {
7363
this.lockTracker.increment(klass, id)
7464
}

packages/client-app/src/flux/nylas-long-connection.es6

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ const Status = {
1818
class NylasLongConnection {
1919
static Status = Status
2020

21-
constructor(api, accountId, opts = {}) {
21+
constructor({api, accountId, ...opts} = {}) {
2222
const {
2323
path,
2424
timeout,
2525
onError,
26+
onResults,
2627
onStatusChanged,
2728
throttleResultsInterval,
2829
closeIfDataStopsInterval,
@@ -42,9 +43,11 @@ class NylasLongConnection {
4243
this._path = path
4344
this._timeout = timeout || CONNECTION_TIMEOUT
4445
this._onError = onError || (() => {})
46+
this._onResults = onResults || (() => {})
4547
this._onStatusChanged = onStatusChanged || (() => {})
4648
this._closeIfDataStopsInterval = closeIfDataStopsInterval
4749

50+
this._emitter.on('results-stopped-arriving', this._onResults)
4851
this._processBufferThrottled = _.throttle(this._processBuffer, PROCESS_BUFFER_THROTTLE, {leading: false})
4952
this._flushResultsSoon = () => {
5053
if (this._results.length === 0) { return }
@@ -93,10 +96,6 @@ class NylasLongConnection {
9396
this._onStatusChanged(this._status, this._httpStatusCode)
9497
}
9598

96-
onResults(callback) {
97-
this._emitter.on('results-stopped-arriving', callback)
98-
}
99-
10099
onError(error) {
101100
this._onError(error)
102101
}

0 commit comments

Comments
 (0)