@@ -77,7 +77,7 @@ export class PersistentConnection extends ServerActions {
77
77
private log_ = logWrapper ( 'p:' + this . id + ':' ) ;
78
78
79
79
private interruptReasons_ : { [ reason : string ] : boolean } = { } ;
80
- private listens_ : { [ path : string ] : { [ queryId : string ] : ListenSpec } } = { } ;
80
+ private listens_ : Map < string , Map < string , ListenSpec > > = new Map ( ) ;
81
81
private outstandingPuts_ : OutstandingPut [ ] = [ ] ;
82
82
private outstandingPutCount_ = 0 ;
83
83
private onDisconnectRequestQueue_ : OnDisconnectRequest [ ] = [ ] ;
@@ -180,14 +180,14 @@ export class PersistentConnection extends ServerActions {
180
180
const queryId = query . queryIdentifier ( ) ;
181
181
const pathString = query . path . toString ( ) ;
182
182
this . log_ ( 'Listen called for ' + pathString + ' ' + queryId ) ;
183
- this . listens_ [ pathString ] = this . listens_ [ pathString ] || { } ;
183
+ this . listens_ . set ( pathString , this . listens_ . get ( pathString ) || new Map ( ) ) ;
184
184
assert (
185
185
query . getQueryParams ( ) . isDefault ( ) ||
186
186
! query . getQueryParams ( ) . loadsAllData ( ) ,
187
187
'listen() called for non-default but complete query'
188
188
) ;
189
189
assert (
190
- ! this . listens_ [ pathString ] [ queryId ] ,
190
+ ! this . listens_ . get ( pathString ) ! . get ( queryId ) ,
191
191
'listen() called twice for same path/queryId.'
192
192
) ;
193
193
const listenSpec : ListenSpec = {
@@ -196,7 +196,7 @@ export class PersistentConnection extends ServerActions {
196
196
query : query ,
197
197
tag : tag
198
198
} ;
199
- this . listens_ [ pathString ] [ queryId ] = listenSpec ;
199
+ this . listens_ . get ( pathString ) ! . set ( queryId , listenSpec ) ;
200
200
201
201
if ( this . connected_ ) {
202
202
this . sendListen_ ( listenSpec ) ;
@@ -228,7 +228,8 @@ export class PersistentConnection extends ServerActions {
228
228
PersistentConnection . warnOnListenWarnings_ ( payload , query ) ;
229
229
230
230
const currentListenSpec =
231
- this . listens_ [ pathString ] && this . listens_ [ pathString ] [ queryId ] ;
231
+ this . listens_ . has ( pathString ) &&
232
+ this . listens_ . get ( pathString ) ! . get ( queryId ) ;
232
233
// only trigger actions if the listen hasn't been removed and readded
233
234
if ( currentListenSpec === listenSpec ) {
234
235
this . log_ ( 'listen response' , message ) ;
@@ -834,11 +835,12 @@ export class PersistentConnection extends ServerActions {
834
835
private removeListen_ ( pathString : string , queryId : string ) : ListenSpec {
835
836
const normalizedPathString = new Path ( pathString ) . toString ( ) ; // normalize path.
836
837
let listen ;
837
- if ( this . listens_ [ normalizedPathString ] !== undefined ) {
838
- listen = this . listens_ [ normalizedPathString ] [ queryId ] ;
839
- delete this . listens_ [ normalizedPathString ] [ queryId ] ;
840
- if ( isEmpty ( this . listens_ [ normalizedPathString ] ) ) {
841
- delete this . listens_ [ normalizedPathString ] ;
838
+ if ( this . listens_ . has ( normalizedPathString ) ) {
839
+ const map = this . listens_ . get ( normalizedPathString ) ! ;
840
+ listen = map . get ( queryId ) ;
841
+ map . delete ( queryId ) ;
842
+ if ( map . size === 0 ) {
843
+ this . listens_ . delete ( normalizedPathString ) ;
842
844
}
843
845
} else {
844
846
// all listens for this path has already been removed
@@ -884,8 +886,8 @@ export class PersistentConnection extends ServerActions {
884
886
885
887
// Puts depend on having received the corresponding data update from the server before they complete, so we must
886
888
// make sure to send listens before puts.
887
- for ( const queries of Object . values ( this . listens_ ) ) {
888
- for ( const listenSpec of Object . values ( queries ) ) {
889
+ for ( const queries of this . listens_ . values ( ) ) {
890
+ for ( const listenSpec of queries . values ( ) ) {
889
891
this . sendListen_ ( listenSpec ) ;
890
892
}
891
893
}
0 commit comments