Skip to content

Add FieldValue methods to the Lite SDK #3135

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 9 commits into from
Jun 2, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian commented May 29, 2020

This PR adds the FieldValue methods to the Lite SDK.

It also solves a problem with the FieldValue methods in the current ("legacy") SDK. Our API promises that the FieldValue implementations returned by FieldValue.insertNameHere() methods are an instance of FieldValue. This was not the case anymore. I solved this by adding a wrapper type that wraps the FieldValue class in the Lite and Legacy SDK, which allows both SDKs to use different FieldValue types without duplicating all implementations.

This PR also prefixes the internal "toFieldTransform" method with an underscore since this is a class returned by the public API.

@schmidt-sebastian schmidt-sebastian removed the request for review from dconeybe May 29, 2020 17:39
@schmidt-sebastian schmidt-sebastian changed the title Add FieldValue methods to the Lite SDK WIP Add FieldValue methods to the Lite SDK May 29, 2020
@schmidt-sebastian schmidt-sebastian force-pushed the mrschmidt/fieldvalue branch 3 times, most recently from e50a76f to ae95648 Compare May 29, 2020 18:27
@schmidt-sebastian schmidt-sebastian changed the title WIP Add FieldValue methods to the Lite SDK Add FieldValue methods to the Lite SDK May 29, 2020
@schmidt-sebastian
Copy link
Contributor Author

@dconeybe I think this is now ready for review (sorry for assigning this earlier). This ended up being a lot tricker (read: uglier) that I had hoped for. Let me know if you need help reviewing/want to send this somewhere else.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 29, 2020

Binary Size Report

Affected SDKs

  • @firebase/firestore

    Type Base (6e6dbe2) Head (7b03849) Diff
    browser 252 kB 251 kB -333 B (-0.1%)
    esm2017 195 kB 195 kB -136 B (-0.1%)
    main 494 kB 494 kB -274 B (-0.1%)
    module 249 kB 249 kB -386 B (-0.2%)
  • @firebase/firestore/lite

    Type Base (6e6dbe2) Head (7b03849) Diff
    main 6.51 kB 102 kB +95.3 kB (+1463.3%)
  • @firebase/firestore/memory

    Type Base (6e6dbe2) Head (7b03849) Diff
    browser 192 kB 191 kB -300 B (-0.2%)
    esm2017 149 kB 149 kB -228 B (-0.2%)
    main 370 kB 370 kB -197 B (-0.1%)
    module 190 kB 190 kB -353 B (-0.2%)
  • @firebase/util

    Type Base (6e6dbe2) Head (7b03849) Diff
    browser 19.5 kB 19.6 kB +143 B (+0.7%)
    esm2017 17.4 kB 17.5 kB +126 B (+0.7%)
    main 19.5 kB 19.6 kB +143 B (+0.7%)
    module 18.6 kB 18.7 kB +126 B (+0.7%)
  • firebase

    Type Base (6e6dbe2) Head (7b03849) Diff
    firebase-firestore.js 290 kB 290 kB -392 B (-0.1%)
    firebase-firestore.memory.js 232 kB 232 kB -361 B (-0.2%)
    firebase.js 823 kB 823 kB -387 B (-0.0%)

Test Logs

export function arrayUnion(...elements: unknown[]): firestore.FieldValue {
validateAtLeastNumberOfArgs('arrayUnion()', arguments, 1);
// NOTE: We don't actually parse the data until it's used in set() or
// update() since we need access to the Firestore instance.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider tweaking this part of the sentence to read: "since we'd need the Firestore instance to do this." (also on line 87).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (4x times)

expectEqual(FieldValue.delete(), FieldValue.delete());
expectEqual(FieldValue.serverTimestamp(), FieldValue.serverTimestamp());
expectNotEqual(FieldValue.delete(), FieldValue.serverTimestamp());
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test case to exercise the if (!(other instanceof FieldValueDelegate)) block of isEqual().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added TODO to do this when documentId() is merged into master.

@@ -24,4 +25,12 @@ describe('FieldValue', () => {
expectEqual(FieldValue.serverTimestamp(), FieldValue.serverTimestamp());
expectNotEqual(FieldValue.delete(), FieldValue.serverTimestamp());
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a test here as well for calling isEqual() with an object that is not an instanceof FieldValue (e.g. a string).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: I reverted it since FieldPath.documentId() throws if I pass a FieldValue, and the FieldValue constructor is typed to only take FieldValues.

@schmidt-sebastian schmidt-sebastian merged commit 7453b0e into master Jun 2, 2020
@firebase firebase locked and limited conversation to collaborators Jul 3, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/fieldvalue branch November 9, 2020 22:39
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.

3 participants