-
Notifications
You must be signed in to change notification settings - Fork 938
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
Conversation
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.
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 |
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.
Can we just check obj._delegate
instead of relying on instanceof
ing the abstract class, so that I can put it into @firebase/util
and share with other SDKs?
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.
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?
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.
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.
To answer your question -I am envisioning a world where all types are fully exchangeable. The user will not need to do any casting. |
@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 |
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.
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.
|
This PR allows all firestore-exp APIs to transparently accept Compat types, which makes migration for the user easier.