55// 'npm run snippets'.
66
77// [START initialize_persistence_modular]
8- import { enableIndexedDbPersistence } from "firebase/firestore" ;
8+ // Memory cache is the default if no config is specified.
9+ initializeFirestore ( app , { } ) ;
910
10- enableIndexedDbPersistence ( db )
11- . catch ( ( err ) => {
12- if ( err . code == 'failed-precondition' ) {
13- // Multiple tabs open, persistence can only be enabled
14- // in one tab at a a time.
15- // ...
16- } else if ( err . code == 'unimplemented' ) {
17- // The current browser does not support all of the
18- // features required to enable persistence
19- // ...
20- }
11+ // This is the default behavior if no persistence is specified.
12+ initializeFirestore ( app , { localCache : memoryLocalCache ( ) } ) ;
13+
14+ // Defaults to single-tab persistence if no tab manager is specified.
15+ initializeFirestore ( app , { localCache : persistentLocalCache ( /*settings*/ { } ) } ) ;
16+
17+ // Same as `initializeFirestore(app, {localCache: persistentLocalCache(/*settings*/{})})`,
18+ // but more explicit about tab management.
19+ initializeFirestore ( app ,
20+ { localCache :
21+ persistentLocalCache ( /*settings*/ { tabManager : persistentSingleTabManager ( { } ) } )
22+ } ) ;
23+
24+ // Use multi-tab IndexedDb persistence.
25+ initializeFirestore ( app ,
26+ { localCache :
27+ persistentLocalCache ( /*settings*/ { tabManager : persistentMultipleTabManager ( ) } )
2128 } ) ;
22- // Subsequent queries will use persistence, if it was enabled successfully
2329// [END initialize_persistence_modular]
0 commit comments