Skip to content

Compat class for QuerySnapshot #4058

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

Merged
merged 4 commits into from
Nov 12, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2020

⚠️ No Changeset found

Latest commit: 543bc77

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When 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

@@ -403,17 +402,108 @@ export class QuerySnapshot<T = DocumentData> {
!this._cachedChanges ||
this._cachedChangesIncludeMetadataChanges !== includeMetadataChanges
) {
this._cachedChanges = changesFromSnapshot<QueryDocumentSnapshot<T>>(
this._cachedChanges = this.changesFromSnapshot(
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a nontrivial amount of code here and if you don't actually use docChanges this could be tree-shaken away. This change to make changesFromSnapshot a member works against ever being able to make docChanges a free function in our public API.

To me this suggests a general design principle of trying to absolutely minimize the number of member functions we keep in classes.

In this case, it seems like it would be straightforward to transplant the changesFromSnapshot function here.

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 updated this, but I am not sure if this is a stylistic win (and probably not in terms of code size(. It does reduce the amount of code changes in this PR, even though I replaced the factory-function signature with an inline instantiation of the now "hardcoded" QueryDocumentSnapshot.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I constantly struggle with my visceral dislike of the style we've adopted to make tree-shakeable APIs a reality. It's ugly, I don't like it, but I have to get over it because this is where JavaScript is going.

Part of my reasoning for pushing for a blanket rule on member vs free is to remove this decision from the realm of style. I see the local style suboptimality of free functions as a net win because it makes things more consistent and removes the need to reason about how to add the next function.

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Nov 12, 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.

LGTM

@@ -403,17 +402,108 @@ export class QuerySnapshot<T = DocumentData> {
!this._cachedChanges ||
this._cachedChangesIncludeMetadataChanges !== includeMetadataChanges
) {
this._cachedChanges = changesFromSnapshot<QueryDocumentSnapshot<T>>(
this._cachedChanges = this.changesFromSnapshot(
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I constantly struggle with my visceral dislike of the style we've adopted to make tree-shakeable APIs a reality. It's ugly, I don't like it, but I have to get over it because this is where JavaScript is going.

Part of my reasoning for pushing for a blanket rule on member vs free is to remove this decision from the realm of style. I see the local style suboptimality of free functions as a net win because it makes things more consistent and removes the need to reason about how to add the next function.

@firebase firebase deleted a comment from google-oss-bot Nov 12, 2020
@schmidt-sebastian schmidt-sebastian merged commit 5ba4c26 into master Nov 12, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/querysnapshot-compat branch November 12, 2020 23:20
@firebase firebase locked and limited conversation to collaborators Dec 13, 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.

2 participants