Skip to content

Make Document.field() nullable #1927

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 3 commits into from
Jun 28, 2019
Merged

Make Document.field() nullable #1927

merged 3 commits into from
Jun 28, 2019

Conversation

schmidt-sebastian
Copy link
Contributor

Small cleanup PR to make us do less of doc.field(path) || null.

Note that the Public API still returns undefined for missing fields (to differentiate from null), but the private API doesn't need to since it returns a wrapped FieldValue.

field(path: FieldPath): FieldValue | undefined {
return this.data.field(path);
field(path: FieldPath): FieldValue | null {
return this.data.field(path) || null;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like this PR replaces 2 || nulls with 1 || null which is technically better, I guess... except now we have two different field() methods (one on Document and one on ObjectValue) that treat nonexistence differently (one as null, one as undefined) which seems worse.

If we're going to make this change, I think we should probably at least plumb it down into ObjectValue.field() as well...

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Jun 28, 2019

Choose a reason for hiding this comment

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

I added two more "|| null" in #1928 and made an internal value of type "FieldValue | undefined" instead of "undefined" (https://github.com/firebase/firebase-js-sdk/pull/1928/files#diff-af007bc1ca0cf1509f29df38bed7d308R693) which I think is pretty ugly.

I also changed ObjectValue.

@schmidt-sebastian schmidt-sebastian merged commit be8940f into master Jun 28, 2019
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/null branch June 28, 2019 21:48
@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants