@@ -78,7 +78,6 @@ interface OutstandingPut {
78
78
}
79
79
80
80
interface OutstandingGet {
81
- action : string ;
82
81
request : object ;
83
82
onComplete : ( response : { [ k : string ] : unknown } ) => void ;
84
83
}
@@ -223,18 +222,22 @@ export class PersistentConnection extends ServerActions {
223
222
const index = this . outstandingGets_ . length - 1 ;
224
223
225
224
if ( ! this . connected_ ) {
226
- const self = this ;
227
225
setTimeout ( ( ) => {
228
- const get = self . outstandingGets_ [ index ] ;
226
+ const get = this . outstandingGets_ [ index ] ;
229
227
if ( get === undefined || outstandingGet !== get ) {
230
228
return ;
231
229
}
232
- delete self . outstandingGets_ [ index ] ;
233
- self . outstandingGetCount_ -- ;
234
- if ( self . outstandingGetCount_ === 0 ) {
235
- self . outstandingGets_ = [ ] ;
230
+ delete this . outstandingGets_ [ index ] ;
231
+ this . outstandingGetCount_ -- ;
232
+ if ( this . outstandingGetCount_ === 0 ) {
233
+ this . outstandingGets_ = [ ] ;
236
234
}
237
- self . log_ ( 'get ' + index + ' timed out on connection' ) ;
235
+ this . log_ ( 'get ' + index + ' timed out on connection' ) ;
236
+ // It's possible that we were once able to reach the server,
237
+ // but not anymore. If that's the case, the client could have
238
+ // an active listener with cached data for this get. The Repo
239
+ // will try to retrieve this cached data if we can't connect
240
+ // here.
238
241
deferred . reject ( new Error ( 'Client is offline.' ) ) ;
239
242
} , GET_CONNECT_TIMEOUT ) ;
240
243
}
@@ -263,7 +266,7 @@ export class PersistentConnection extends ServerActions {
263
266
}
264
267
assert (
265
268
query . getQueryParams ( ) . isDefault ( ) ||
266
- ! query . getQueryParams ( ) . loadsAllData ( ) ,
269
+ ! query . getQueryParams ( ) . loadsAllData ( ) ,
267
270
'listen() called for non-default but complete query'
268
271
) ;
269
272
assert (
@@ -285,20 +288,16 @@ export class PersistentConnection extends ServerActions {
285
288
286
289
private sendGet_ ( index : number ) {
287
290
const get = this . outstandingGets_ [ index ] ;
288
- this . sendRequest (
289
- get . action ,
290
- get . request ,
291
- ( message : { [ k : string ] : unknown } ) => {
292
- delete this . outstandingGets_ [ index ] ;
293
- this . outstandingGetCount_ -- ;
294
- if ( this . outstandingGetCount_ === 0 ) {
295
- this . outstandingGets_ = [ ] ;
296
- }
297
- if ( get . onComplete ) {
298
- get . onComplete ( message ) ;
299
- }
291
+ this . sendRequest ( 'g' , get . request , ( message : { [ k : string ] : unknown } ) => {
292
+ delete this . outstandingGets_ [ index ] ;
293
+ this . outstandingGetCount_ -- ;
294
+ if ( this . outstandingGetCount_ === 0 ) {
295
+ this . outstandingGets_ = [ ] ;
300
296
}
301
- ) ;
297
+ if ( get . onComplete ) {
298
+ get . onComplete ( message ) ;
299
+ }
300
+ } ) ;
302
301
}
303
302
304
303
private sendListen_ ( listenSpec : ListenSpec ) {
@@ -353,8 +352,8 @@ export class PersistentConnection extends ServerActions {
353
352
const indexPath = query . path . toString ( ) ;
354
353
warn (
355
354
`Using an unspecified index. Your data will be downloaded and ` +
356
- `filtered on the client. Consider adding ${ indexSpec } at ` +
357
- `${ indexPath } to your security rules for better performance.`
355
+ `filtered on the client. Consider adding ${ indexSpec } at ` +
356
+ `${ indexPath } to your security rules for better performance.`
358
357
) ;
359
358
}
360
359
}
@@ -372,7 +371,7 @@ export class PersistentConnection extends ServerActions {
372
371
//If we're connected we want to let the server know to unauthenticate us. If we're not connected, simply delete
373
372
//the credential so we dont become authenticated next time we connect.
374
373
if ( this . connected_ ) {
375
- this . sendRequest ( 'unauth' , { } , ( ) => { } ) ;
374
+ this . sendRequest ( 'unauth' , { } , ( ) => { } ) ;
376
375
}
377
376
}
378
377
@@ -436,7 +435,7 @@ export class PersistentConnection extends ServerActions {
436
435
437
436
assert (
438
437
query . getQueryParams ( ) . isDefault ( ) ||
439
- ! query . getQueryParams ( ) . loadsAllData ( ) ,
438
+ ! query . getQueryParams ( ) . loadsAllData ( ) ,
440
439
'unlisten() called for non-default but complete query'
441
440
) ;
442
441
const listen = this . removeListen_ ( pathString , queryId ) ;
@@ -694,8 +693,8 @@ export class PersistentConnection extends ServerActions {
694
693
} else {
695
694
error (
696
695
'Unrecognized action received from server: ' +
697
- stringify ( action ) +
698
- '\nAre you using the latest client?'
696
+ stringify ( action ) +
697
+ '\nAre you using the latest client?'
699
698
) ;
700
699
}
701
700
}
0 commit comments