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

Make clearIndexedDbPersistence() work without enableIndexedDbPersistence() #3373

Merged
merged 5 commits into from
Jul 9, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented Jul 8, 2020

In the current firestore-exp client, clearIndexedDbPersistence() cannot be called on an uninitialized instance since the IndexedDbComponentProvider is not registered. This PR changes the plumbing so that clearIndexedDbPersistence() brings all logic that it needs to perform the delete without pulling in IndexedDbPersistence or the IndexedDbComponentProvider.

Note that I did update the dependencies file, but the firestore-exp client is currently so bad at being "tree-shaken" that the dependencies don't make much sense.

@changeset-bot
Copy link

changeset-bot bot commented Jul 8, 2020

🦋 Changeset is good to go

Latest commit: 0845047

We got this.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 8, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (9b53ec8) Head (e210724) Diff
    browser 247 kB 247 kB -36 B (-0.0%)
    esm2017 194 kB 194 kB -35 B (-0.0%)
    main 495 kB 495 kB -138 B (-0.0%)
    module 245 kB 245 kB -36 B (-0.0%)
    react-native 194 kB 194 kB -35 B (-0.0%)
  • @firebase/firestore/exp

    Type Base (9b53ec8) Head (e210724) Diff
    main 400 kB 400 kB -102 B (-0.0%)
  • @firebase/firestore/memory

    Type Base (9b53ec8) Head (e210724) Diff
    browser 185 kB 185 kB +2 B (+0.0%)
    esm2017 145 kB 145 kB -2 B (-0.0%)
    main 364 kB 364 kB -12 B (-0.0%)
    module 183 kB 183 kB +2 B (+0.0%)
    react-native 145 kB 145 kB -2 B (-0.0%)
  • firebase

    Type Base (9b53ec8) Head (e210724) Diff
    firebase-firestore.js 285 kB 285 kB -41 B (-0.0%)
    firebase-firestore.memory.js 224 kB 224 kB +2 B (+0.0%)
    firebase.js 819 kB 819 kB -41 B (-0.0%)

Test Logs

@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/expshim to master July 9, 2020 05:09
@schmidt-sebastian schmidt-sebastian changed the title Meake clearIndexedDbPersistence() work without enableIndexedDbPersistence() Make clearIndexedDbPersistence() work without enableIndexedDbPersistence() Jul 9, 2020
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot be called on an initialized instance

Did you mean on an uninitialized instance? If so, this PR makes more sense.

@@ -1,6 +1,6 @@
/**
* @license
* Copyright 2017 Google Inc.
* Copyright 2017 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes seem unrelated. Revert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. I actually tried to remove them earlier, but the pre commit hook brought them back in. I had to disable the precommit hook for this commit.

@@ -247,7 +254,9 @@ export function clearIndexedDbPersistence(
firestore: firestore.FirebaseFirestore
): Promise<void> {
const firestoreImpl = cast(firestore, Firestore);
return firestoreImpl._clearPersistence();
return firestoreImpl._clearPersistence((databaseId, persistenceKey) => {
return clearPersistence(buildStoragePrefix(databaseId, persistenceKey));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code reads as if it's circular unless you pay careful attention. If clearPersistence were named indexedDbClearPersistence it would be clearer that the higher level API was delegating to the lower-level implementation.

I realize this is getting at that type-operation naming discussion we started earlier so feel free to defer if you must, but I think it's really hurting the ability to understand what's going on here while reading the code directly. Sure you can go look at the imports but that breaks flow. Reading code is hard enough and we should strive to make it easy to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stumbled across this earlier too, but didn't act upon my confusion. I think a minimum bar for code quality should be that at the very least the person writing it shouldn't be confused...

Renamed to indexedDbClearPersistence and indexedDbStoragePrefix.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@schmidt-sebastian schmidt-sebastian merged commit 0b14a8c into master Jul 9, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/fixclear branch July 9, 2020 17:43
@firebase firebase locked and limited conversation to collaborators Aug 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants