-
Notifications
You must be signed in to change notification settings - Fork 946
Optional Datastore/FirestoreClient #3382
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
Conversation
💥 No ChangesetLatest commit: 5f22a4e Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂 If these changes should be published to npm, you need to add a changeset. This PR includes no changesetsWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Click here to learn what changesets are, and how to add one. Click here if you're a maintainer who wants to add a changeset to this PR |
Binary Size ReportAffected SDKs
Test Logs
|
bc64fd0
to
d7dd84e
Compare
Pretty sure this is causes the CI failure in #3382
@rafikhan Do you have time to review this? |
3b24b7a
to
2bac522
Compare
I updated the PR to use a more generic mechanism for component removal - see 2bac522. Note that for now only one component exists so the difference is minimal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments around logging and factoring out functions. Otherwise LGTM.
const settings = firestore._getSettings(); | ||
const databaseInfo = new DatabaseInfo( | ||
firestore._databaseId, | ||
firestore._persistenceKey, | ||
settings.host ?? DEFAULT_HOST, | ||
settings.ssl ?? DEFAULT_SSL, | ||
/* forceLongPolling= */ false | ||
); | ||
const datastorePromise = newConnection(databaseInfo).then(connection => { | ||
const serializer = newSerializer(databaseInfo.databaseId); | ||
const datastore = newDatastore(firestore._credentials, serializer); | ||
datastore.start(connection); | ||
return datastore; | ||
}); | ||
datastoreInstances.set(firestore, datastorePromise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add appropriate logging during instantiation and removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if (firestoreImpl._initialized && !firestoreImpl._terminated) { | ||
throw new FirestoreError( | ||
Code.FAILED_PRECONDITION, | ||
'Persistence can only be cleared before a Firestore instance is ' + | ||
'initialized or after it is terminated.' | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Consider putting this into an assert method like assertIsNotInitialized()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept as is for now since this is the only callsite and the only method that I am aware of that has this contract (plus I would have to come up with a good name - assertIsNotInitialized is only 90% correct...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
cc3452f
to
81755fc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This implements a proposal for optional dependencies discussed in the
firebase-js-sdk
chatroom. We currently have:This means that any user of
Firestore
will pull in Datastore and FirestoreClient, even if they were to just useTimestamp
or (more realistically) the new methods that only read from cache.To solve this problem, I added a
components.ts
file for both the Lite SDK and the firestore-exp SDK that manages the relationship between Firestore and its components. Each Firestore instance has up to one component, and the Firestore class is responsible for its cleanup (via theremoveMethods
).To make this worthwhile I also move the
ComponentProvider
initialization intocomponents.ts
, which has some impact onenableIndexedDbPersistence
andclearIndexdDbPersistence
.The first commit contains the code changes, the second commit contains the updated dependency file (auto-generated).