@@ -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 readonly 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,16 @@ 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
+ if ( ! this . listens . has ( pathString ) ) {
184
+ this . listens . set ( pathString , new Map ( ) ) ;
185
+ }
184
186
assert (
185
187
query . getQueryParams ( ) . isDefault ( ) ||
186
188
! query . getQueryParams ( ) . loadsAllData ( ) ,
187
189
'listen() called for non-default but complete query'
188
190
) ;
189
191
assert (
190
- ! this . listens_ [ pathString ] [ queryId ] ,
192
+ ! this . listens . get ( pathString ) ! . has ( queryId ) ,
191
193
'listen() called twice for same path/queryId.'
192
194
) ;
193
195
const listenSpec : ListenSpec = {
@@ -196,7 +198,7 @@ export class PersistentConnection extends ServerActions {
196
198
query : query ,
197
199
tag : tag
198
200
} ;
199
- this . listens_ [ pathString ] [ queryId ] = listenSpec ;
201
+ this . listens . get ( pathString ) ! . set ( queryId , listenSpec ) ;
200
202
201
203
if ( this . connected_ ) {
202
204
this . sendListen_ ( listenSpec ) ;
@@ -228,7 +230,8 @@ export class PersistentConnection extends ServerActions {
228
230
PersistentConnection . warnOnListenWarnings_ ( payload , query ) ;
229
231
230
232
const currentListenSpec =
231
- this . listens_ [ pathString ] && this . listens_ [ pathString ] [ queryId ] ;
233
+ this . listens . get ( pathString ) &&
234
+ this . listens . get ( pathString ) ! . get ( queryId ) ;
232
235
// only trigger actions if the listen hasn't been removed and readded
233
236
if ( currentListenSpec === listenSpec ) {
234
237
this . log_ ( 'listen response' , message ) ;
@@ -834,11 +837,12 @@ export class PersistentConnection extends ServerActions {
834
837
private removeListen_ ( pathString : string , queryId : string ) : ListenSpec {
835
838
const normalizedPathString = new Path ( pathString ) . toString ( ) ; // normalize path.
836
839
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 ] ;
840
+ if ( this . listens . has ( normalizedPathString ) ) {
841
+ const map = this . listens . get ( normalizedPathString ) ! ;
842
+ listen = map . get ( queryId ) ;
843
+ map . delete ( queryId ) ;
844
+ if ( map . size === 0 ) {
845
+ this . listens . delete ( normalizedPathString ) ;
842
846
}
843
847
} else {
844
848
// all listens for this path has already been removed
@@ -884,8 +888,8 @@ export class PersistentConnection extends ServerActions {
884
888
885
889
// Puts depend on having received the corresponding data update from the server before they complete, so we must
886
890
// make sure to send listens before puts.
887
- for ( const queries of Object . values ( this . listens_ ) ) {
888
- for ( const listenSpec of Object . values ( queries ) ) {
891
+ for ( const queries of this . listens . values ( ) ) {
892
+ for ( const listenSpec of queries . values ( ) ) {
889
893
this . sendListen_ ( listenSpec ) ;
890
894
}
891
895
}
0 commit comments