Skip to content

Accept Compat types in firestore-exp API #4056

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 8 commits into from
Nov 21, 2020
Merged

Conversation

schmidt-sebastian
Copy link
Contributor

This PR allows all firestore-exp APIs to transparently accept Compat types, which makes migration for the user easier.

Copy link
Member

@Feiyang1 Feiyang1 left a comment

Choose a reason for hiding this comment

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

I really like the approach as it makes it seamless to use compat and exp side by side. My only question is (asked in the comment too) - do people need to cast the compat type to the exp type in order to use the exp API?

@@ -166,7 +166,8 @@ export function tryGetCustomObjectType(input: object): string | null {
}

/**
* Casts `obj` to `T`. Throws if `obj` is not an instance of `T`.
* Casts `obj` to `T`, optionally unwrapping Compat types to expose the
Copy link
Member

Choose a reason for hiding this comment

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

Can we just check obj._delegate instead of relying on instanceofing the abstract class, so that I can put it into @firebase/util and share with other SDKs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. This function also does a name check and provides a different error message if there it detects that two classes share the same name but are not compatible. I was wondering if we need to strip suffixes here, since Rollup adds "$1" and counting during the build phase?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Yes, rollup will append $x to things with the same name if they end up in the same bundle. I'm not sure if it's the case with webpack which creates many closures instead of one big top level scope. I think it very much depends on the format of the bundle, thus is hard for us to predict/optimize for. I would just leave it as is for now and see if developer reports that the error is not helpful.

@schmidt-sebastian
Copy link
Contributor Author

To answer your question -I am envisioning a world where all types are fully exchangeable. The user will not need to do any casting.

@schmidt-sebastian
Copy link
Contributor Author

@Feiyang1 Can you take another look?

@@ -166,7 +166,8 @@ export function tryGetCustomObjectType(input: object): string | null {
}

/**
* Casts `obj` to `T`. Throws if `obj` is not an instance of `T`.
* Casts `obj` to `T`, optionally unwrapping Compat types to expose the
Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Yes, rollup will append $x to things with the same name if they end up in the same bundle. I'm not sure if it's the case with webpack which creates many closures instead of one big top level scope. I think it very much depends on the format of the bundle, thus is hard for us to predict/optimize for. I would just leave it as is for now and see if developer reports that the error is not helpful.

@firebase firebase deleted a comment from changeset-bot bot Nov 20, 2020
@firebase firebase deleted a comment from google-oss-bot Nov 20, 2020
@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2020

⚠️ No Changeset found

Latest commit: 3eb33e3

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

@firebase firebase deleted a comment from google-oss-bot Nov 21, 2020
@schmidt-sebastian schmidt-sebastian merged commit 4ffb664 into master Nov 21, 2020
@firebase firebase locked and limited conversation to collaborators Dec 21, 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