1
1
import { next } from '@ember/runloop' ;
2
2
import DS from 'ember-data' ;
3
- import ModelRegistry from 'ember-data/types/registries/model' ;
3
+ import type ModelRegistry from 'ember-data/types/registries/model' ;
4
4
import Service , { inject as service } from '@ember/service' ;
5
5
import StoreService from '@ember-data/store' ;
6
6
7
- import {
7
+ import type {
8
8
CollectionReference ,
9
9
DocumentReference ,
10
10
DocumentSnapshot ,
@@ -96,7 +96,7 @@ export default class FirestoreDataManager extends Service {
96
96
await this . setupDocRealtimeUpdates ( modelName , docRef ) ;
97
97
}
98
98
99
- return this . docListeners [ listenerKey ] . snapshot ;
99
+ return this . docListeners [ listenerKey ] ? .snapshot ! ;
100
100
}
101
101
102
102
public async findAllRealtime (
@@ -109,7 +109,7 @@ export default class FirestoreDataManager extends Service {
109
109
await this . setupColRealtimeUpdates ( modelName , colRef ) ;
110
110
}
111
111
112
- return this . colListeners [ listenerKey ] . snapshot ;
112
+ return this . colListeners [ listenerKey ] ? .snapshot ! ;
113
113
}
114
114
115
115
public async queryRealtime (
@@ -120,7 +120,7 @@ export default class FirestoreDataManager extends Service {
120
120
let unsubscribe : Unsubscribe | undefined ;
121
121
122
122
if ( this . queryListeners [ queryId ] ) {
123
- unsubscribe = this . queryListeners [ queryId ] . unsubscribe ;
123
+ unsubscribe = this . queryListeners [ queryId ] ? .unsubscribe ;
124
124
delete this . queryListeners [ queryId ] ;
125
125
}
126
126
@@ -130,7 +130,7 @@ export default class FirestoreDataManager extends Service {
130
130
unsubscribe ( ) ;
131
131
}
132
132
133
- return this . queryListeners [ queryId ] . snapshots ;
133
+ return this . queryListeners [ queryId ] ? .snapshots ! ;
134
134
}
135
135
136
136
public async findHasManyRealtime (
@@ -141,7 +141,7 @@ export default class FirestoreDataManager extends Service {
141
141
let unsubscribe : Unsubscribe | undefined ;
142
142
143
143
if ( this . hasManyListeners [ queryId ] ) {
144
- unsubscribe = this . hasManyListeners [ queryId ] . unsubscribe ;
144
+ unsubscribe = this . hasManyListeners [ queryId ] ? .unsubscribe ;
145
145
delete this . hasManyListeners [ queryId ] ;
146
146
}
147
147
@@ -151,7 +151,7 @@ export default class FirestoreDataManager extends Service {
151
151
unsubscribe ( ) ;
152
152
}
153
153
154
- return this . hasManyListeners [ queryId ] . snapshots ;
154
+ return this . hasManyListeners [ queryId ] ? .snapshots ! ;
155
155
}
156
156
157
157
public async queryWithReferenceTo (
@@ -320,7 +320,7 @@ export default class FirestoreDataManager extends Service {
320
320
listenerKey : string ,
321
321
) : void {
322
322
if ( docSnapshot . exists ( ) ) {
323
- this . docListeners [ listenerKey ] . snapshot = docSnapshot ;
323
+ this . docListeners [ listenerKey ] ! . snapshot = docSnapshot ;
324
324
this . pushRecord ( modelName , docSnapshot ) ;
325
325
} else {
326
326
this . unloadRecord ( modelName , docSnapshot . id , listenerKey ) ;
@@ -332,7 +332,7 @@ export default class FirestoreDataManager extends Service {
332
332
listenerKey : string ,
333
333
querySnapshot : QuerySnapshot ,
334
334
) : void {
335
- this . colListeners [ listenerKey ] . snapshot = querySnapshot ;
335
+ this . colListeners [ listenerKey ] ! . snapshot = querySnapshot ;
336
336
337
337
querySnapshot . forEach ( ( docSnapshot ) => {
338
338
this . pushRecord ( modelName , docSnapshot ) ;
@@ -378,7 +378,7 @@ export default class FirestoreDataManager extends Service {
378
378
// multiple times. Race condition can happen where queryId no longer exists inside
379
379
// queryListeners so we have this check.
380
380
if ( Object . prototype . hasOwnProperty . call ( this . queryListeners , queryId ) ) {
381
- const { unsubscribe } = this . queryListeners [ queryId ] ;
381
+ const { unsubscribe } = this . queryListeners [ queryId ] ! ;
382
382
383
383
delete this . queryListeners [ queryId ] ;
384
384
recordArray . update ( ) . then ( ( ) => unsubscribe ( ) ) ;
@@ -479,22 +479,22 @@ export default class FirestoreDataManager extends Service {
479
479
480
480
private destroyListener ( type : string , key : string ) : void {
481
481
if ( type === 'doc' && this . docListeners [ key ] ) {
482
- this . docListeners [ key ] . unsubscribe ( ) ;
482
+ this . docListeners [ key ] ? .unsubscribe ( ) ;
483
483
delete this . docListeners [ key ] ;
484
484
}
485
485
486
486
if ( type === 'col' && this . colListeners [ key ] ) {
487
- this . colListeners [ key ] . unsubscribe ( ) ;
487
+ this . colListeners [ key ] ? .unsubscribe ( ) ;
488
488
delete this . colListeners [ key ] ;
489
489
}
490
490
491
491
if ( type === 'query' && this . queryListeners [ key ] ) {
492
- this . queryListeners [ key ] . unsubscribe ( ) ;
492
+ this . queryListeners [ key ] ? .unsubscribe ( ) ;
493
493
delete this . queryListeners [ key ] ;
494
494
}
495
495
496
496
if ( type === 'hasMany' && this . hasManyListeners [ key ] ) {
497
- this . hasManyListeners [ key ] . unsubscribe ( ) ;
497
+ this . hasManyListeners [ key ] ? .unsubscribe ( ) ;
498
498
delete this . hasManyListeners [ key ] ;
499
499
}
500
500
}
0 commit comments