@@ -74,22 +74,36 @@ describe("firestore", () => {
7474
7575      const  db  =  getFirestore ( app ) ; 
7676
77+       const  { 
78+         initializeFirestore, 
79+         memoryLocalCache, 
80+         persistentLocalCache, 
81+         persistentSingleTabManager, 
82+         persistentMultipleTabManager
83+       }  =  require ( "firebase/firestore" ) ;  
84+ 
7785      // [START initialize_persistence] 
78-       const  {  enableIndexedDbPersistence }  =  require ( "firebase/firestore" ) ;  
86+       // Memory cache is the default if no config is specified. 
87+       initializeFirestore ( app ,  { } ) ; 
7988
80-       enableIndexedDbPersistence ( db ) 
81-         . catch ( ( err )  =>  { 
82-             if  ( err . code  ==  'failed-precondition' )  { 
83-                 // Multiple tabs open, persistence can only be enabled 
84-                 // in one tab at a a time. 
85-                 // ... 
86-             }  else  if  ( err . code  ==  'unimplemented' )  { 
87-                 // The current browser does not support all of the 
88-                 // features required to enable persistence 
89-                 // ... 
90-             } 
89+       // This is the default behavior if no persistence is specified. 
90+       initializeFirestore ( app ,  { localCache : memoryLocalCache ( ) } ) ; 
91+ 
92+       // Defaults to single-tab persistence if no tab manager is specified. 
93+       initializeFirestore ( app ,  { localCache : persistentLocalCache ( /*settings*/ { } ) } ) ; 
94+ 
95+       // Same as `initializeFirestore(app, {localCache: persistentLocalCache(/*settings*/{})})`, 
96+       // but more explicit about tab management. 
97+       initializeFirestore ( app ,  
98+         { localCache : 
99+           persistentLocalCache ( /*settings*/ { tabManager : persistentSingleTabManager ( { } ) } ) 
100+       } ) ; 
101+ 
102+       // Use multi-tab IndexedDb persistence. 
103+       initializeFirestore ( app ,  
104+         { localCache : 
105+           persistentLocalCache ( /*settings*/ { tabManager : persistentMultipleTabManager ( ) } ) 
91106        } ) ; 
92-       // Subsequent queries will use persistence, if it was enabled successfully 
93107      // [END initialize_persistence] 
94108    } ) ; 
95109
0 commit comments