Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new web persistence #331

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions firestore-next/test.firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,36 @@ describe("firestore", () => {

const db = getFirestore(app);

const {
initializeFirestore,
memoryLocalCache,
persistentLocalCache,
persistentSingleTabManager,
persistentMultipleTabManager
} = require("firebase/firestore");

// [START initialize_persistence]
const { enableIndexedDbPersistence } = require("firebase/firestore");
// Memory cache is the default if no config is specified.
initializeFirestore(app);

enableIndexedDbPersistence(db)
.catch((err) => {
if (err.code == 'failed-precondition') {
// Multiple tabs open, persistence can only be enabled
// in one tab at a a time.
// ...
} else if (err.code == 'unimplemented') {
// The current browser does not support all of the
// features required to enable persistence
// ...
}
// This is the default behavior if no persistence is specified.
initializeFirestore(app, {localCache: memoryLocalCache()});

// Defaults to single-tab persistence if no tab manager is specified.
initializeFirestore(app, {localCache: persistentLocalCache(/*settings*/{})});

// Same as `initializeFirestore(app, {localCache: persistentLocalCache(/*settings*/{})})`,
// but more explicit about tab management.
initializeFirestore(app,
{localCache:
persistentLocalCache(/*settings*/{tabManager: persistentSingleTabManager()})
});

// Use multi-tab IndexedDb persistence.
initializeFirestore(app,
{localCache:
persistentLocalCache(/*settings*/{tabManager: persistentMultipleTabManager()})
});
// Subsequent queries will use persistence, if it was enabled successfully
// [END initialize_persistence]
});

Expand Down