@@ -45,9 +45,9 @@ export class AngularFireOfflineDatabase {
4545 * A temporary collection of offline writes.
4646 *
4747 * After a refresh, the writes are collected into this queue and emulated locally. When a
48- * connection is available the actual writes are made to Firebase via {@link updateEmulateList }.
48+ * connection is available the actual writes are made to Firebase via {@link processEmulateQue }.
4949 */
50- checkEmulateQue = { } ;
50+ emulateQue = { } ;
5151 /**
5252 * Contains info about offline write processing state
5353 *
@@ -84,15 +84,15 @@ export class AngularFireOfflineDatabase {
8484 const cacheId = Object . keys ( writeCache . cache ) [ this . cacheIndex ] ;
8585 this . cacheIndex ++ ;
8686 if ( cacheId === undefined ) {
87- this . updateEmulateList ( ) ;
87+ this . processEmulateQue ( ) ;
8888 this . processingComplete ( ) ;
8989 return ;
9090 }
9191 const cacheItem : CacheItem = writeCache . cache [ cacheId ] ;
9292 this [ cacheItem . type ] ( cacheItem . ref ) ; // init item if needed
9393 const sub = this [ `${ cacheItem . type } Cache` ] [ cacheItem . ref ] . sub ;
9494 sub . emulate ( cacheItem . method , ...cacheItem . args ) ;
95- if ( cacheItem . type === 'object' && cacheItem . method === 'set' ) { this . checkEmulateList ( cacheItem ) ; }
95+ if ( cacheItem . type === 'object' && cacheItem . method === 'set' ) { this . addToEmulateQue ( cacheItem ) ; }
9696 this . af . database [ cacheItem . type ] ( cacheItem . ref ) [ cacheItem . method ] ( ...cacheItem . args )
9797 . then ( ( ) => WriteComplete ( cacheId , this . localUpdateService ) ) ;
9898 this . processWrites ( ) ;
@@ -211,20 +211,27 @@ export class AngularFireOfflineDatabase {
211211 } ) ;
212212 }
213213 /**
214- * Adds non-root-level references to the {@link checkEmulateQue}
214+ * Temporarily store offline writes in a que that may be part of a list.
215+ *
216+ * On init the app checks if there were previous offline writes made to objects that may belong
217+ * to a list. This function filters out non-qualifying writes, and puts potential items
218+ * in the {@link emulateQue}. After all offline writes have processed, {@link processEmulateQue}
219+ * runs to piece together objects that belong to a list.
220+ *
221+ * - Filters out root-level object writes because they cannot belong to a list
215222 * @param cacheItem an item from the local write cache
216223 */
217- private checkEmulateList ( cacheItem : CacheItem ) { // add matches to que
224+ private addToEmulateQue ( cacheItem : CacheItem ) { // add matches to que
218225 // Check if root level reference
219226 const refItems : string [ ] = cacheItem . ref . split ( '/' ) ;
220227 refItems . pop ( ) ;
221- const potentialList : string = refItems . join ( '/' ) ;
222- if ( potentialList !== undefined ) {
228+ const potentialListRef : string = refItems . join ( '/' ) ;
229+ if ( potentialListRef !== undefined ) {
223230 // Add
224- if ( ! ( potentialList in this . checkEmulateQue ) ) {
225- this . checkEmulateQue [ potentialList ] = [ ] ;
231+ if ( ! ( potentialListRef in this . emulateQue ) ) {
232+ this . emulateQue [ potentialListRef ] = [ ] ;
226233 }
227- this . checkEmulateQue [ potentialList ] . push ( cacheItem ) ;
234+ this . emulateQue [ potentialListRef ] . push ( cacheItem ) ;
228235 }
229236 }
230237 /**
@@ -282,14 +289,14 @@ export class AngularFireOfflineDatabase {
282289 *
283290 * - only run at startup upon the complete of the {@link processWrites} recursive function
284291 */
285- private updateEmulateList ( ) { // process emulate que
286- Object . keys ( this . checkEmulateQue ) . forEach ( listKey => {
292+ private processEmulateQue ( ) { // process emulate que
293+ Object . keys ( this . emulateQue ) . forEach ( listKey => {
287294 if ( listKey in this . listCache ) {
288295 const sub = this . listCache [ listKey ] . sub ;
289- this . checkEmulateQue [ listKey ] . forEach ( ( cacheItem : CacheItem ) => {
296+ this . emulateQue [ listKey ] . forEach ( ( cacheItem : CacheItem ) => {
290297 sub . emulate ( 'update' , ...cacheItem . args , cacheItem . ref . split ( '/' ) . pop ( ) ) ;
291298 } ) ;
292- delete this . checkEmulateQue [ listKey ] ;
299+ delete this . emulateQue [ listKey ] ;
293300 }
294301 } ) ;
295302 }
0 commit comments