0
0
Firebasecloud~10 mins

Offline persistence in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable offline persistence in Firebase Firestore.

Firebase
firebase.firestore().[1]();
Drag options to blanks, or click blank then click option'
AenablePersistence
BdisablePersistence
CstartPersistence
DsetPersistence
Attempts:
3 left
💡 Hint
Common Mistakes
Using disablePersistence instead of enablePersistence
Trying to call a non-existent method like startPersistence
2fill in blank
medium

Complete the code to catch errors when enabling offline persistence.

Firebase
firebase.firestore().enablePersistence().catch(function([1]) {
  if ([1].code == 'failed-precondition') {
    console.log('Multiple tabs open, persistence failed.');
  }
});
Drag options to blanks, or click blank then click option'
Ae
Berr
Cerror
Dexception
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not matching the catch parameter
Leaving the parameter blank
3fill in blank
hard

Fix the error in the code to enable offline persistence with multi-tab support.

Firebase
firebase.firestore().enablePersistence([1]: true});
Drag options to blanks, or click blank then click option'
AenableMultiTab
BsyncTabs
CmultiTab
DsynchronizeTabs
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option names like syncTabs or multiTab
Missing the curly braces around the option
4fill in blank
hard

Fill both blanks to handle the 'unimplemented' error when enabling persistence.

Firebase
firebase.firestore().enablePersistence().catch(function(error) {
  if (error.code === [1]) {
    console.log('Persistence is not available in this browser.');
  }
  else if (error.code === [2]) {
    console.log('Multiple tabs open, persistence failed.');
  }
});
Drag options to blanks, or click blank then click option'
A'unimplemented'
B'failed-precondition'
C'permission-denied'
D'network-error'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up error codes
Using unrelated error codes like 'permission-denied'
5fill in blank
hard

Fill all three blanks to initialize Firestore with offline persistence and multi-tab synchronization.

Firebase
const db = firebase.firestore();
db.[1]([2]: true).catch(function(error) {
  if (error.code === [3]) {
    console.log('Persistence failed due to multiple tabs.');
  }
});
Drag options to blanks, or click blank then click option'
AenablePersistence
BsynchronizeTabs
C'failed-precondition'
DdisablePersistence
Attempts:
3 left
💡 Hint
Common Mistakes
Using disablePersistence instead of enablePersistence
Wrong option name for multi-tab sync
Incorrect error code in catch block