[client-app] Fix passing cursor to delta streams

Summary:
Currently, when we auth an account for the first time in Nylas Mail (or
we blow away the database), the app is going to request transactions
since cursor `null` from the /delta/streaming endpoint and from the local-sync
delta observable, instead of requesting transactions since cursor `0`

This is due to a subtle bug with the use of default values when
destructuring an object. Our coded did the following:
```
const {cursor = 0} = this._state
```
Which at a glance seems correct. However, this will only work as
expected if `this._state` has the following shape:
```
{cursor: undefined}
```
And unfortunately, our `this._state` looked like this when authing an
account for the first time:
```
{cursor: null}
```

Which would make `cursor === null` instead of `0`.
This is because when using default values, null is considered an
intentional argument/value, as opposed to not passing any argument/value
(which will mean that the argument is undefined).

This was a regression introduced in d60a23c and 8bc2ec5

Test Plan: manual, will add regression test in upcoming diff

Reviewers: evan, spang, halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D4243
This commit is contained in:
Juan Tejada 2017-03-20 15:42:12 -07:00
parent 3909c8885a
commit 3554fb2510
2 changed files with 8 additions and 8 deletions

View file

@ -43,7 +43,7 @@ class DeltaStreamingConnection {
if (!this._state) {
this._state = await this._loadState()
}
const {cursor = 0} = this._state
const cursor = this._state.cursor || 0
this._clearRetryTimeout()
this._longConnection = new NylasLongConnection({
api: N1CloudAPI,
@ -178,8 +178,8 @@ class DeltaStreamingConnection {
const json = await DatabaseStore.findJSONBlob(`DeltaStreamingConnectionStatus:${this._account.id}`)
if (json) {
return {
cursor: json.cursor || null,
status: json.status || null,
cursor: json.cursor || undefined,
status: json.status || undefined,
}
}
@ -187,8 +187,8 @@ class DeltaStreamingConnection {
const oldState = await DatabaseStore.findJSONBlob(`NylasSyncWorker:${this._account.id}`)
if (!oldState) {
return {
cursor: null,
status: null,
cursor: undefined,
status: undefined,
};
}

View file

@ -20,7 +20,7 @@ export default class LocalSyncDeltaEmitter {
if (!this._state) {
this._state = await this._loadState()
}
const {cursor = 0} = this._state
const cursor = this._state.cursor || 0
this._disposable = DeltaStreamBuilder.buildDeltaObservable({
cursor,
db: this._db,
@ -52,7 +52,7 @@ export default class LocalSyncDeltaEmitter {
const json = await DatabaseStore.findJSONBlob(`LocalSyncStatus:${this._account.id}`)
if (json) {
return {
cursor: json.cursor || null,
cursor: json.cursor || undefined,
}
}
@ -60,7 +60,7 @@ export default class LocalSyncDeltaEmitter {
const oldState = await DatabaseStore.findJSONBlob(`NylasSyncWorker:${this._account.id}`)
if (!oldState) {
return {
cursor: null,
cursor: undefined,
}
}