Skip to content

Adds support for pointer/string pointers comparison in LiveQuery #4231

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 5 commits into from
Oct 3, 2017

Conversation

flovilmart
Copy link
Contributor

No description provided.

@flovilmart flovilmart requested a review from acinader October 3, 2017 15:39
@@ -495,4 +495,79 @@ describe('matchesQuery', function() {
expect(matchesQuery(message, q)).toBe(false);

});

function pointer(className, objectId) {
return {__type: 'Pointer', className, objectId };
Copy link
Contributor

Choose a reason for hiding this comment

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

add whitespace between { __

@@ -90,6 +90,28 @@ function queryHash(query) {
}

/**
* contains -- Determines wether a constaint in for form of a list
Copy link
Contributor

Choose a reason for hiding this comment

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

"whether" and "constraint" are misspelled. I haven't read the code yet, but I really can't understand this comment.

@@ -90,6 +90,28 @@ function queryHash(query) {
}

/**
* contains -- Determines wether a constaint in for form of a list
* contains a particular object.
* This also supports, pointer comparion and strings as lightweight pointers
Copy link
Contributor

Choose a reason for hiding this comment

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

"comparison" is misspelled.

if (object.__type && object.__type === 'Pointer') {
for (const i in compareTo) {
const ptr = compareTo[i];
if (typeof ptr == 'string' && ptr === object.objectId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

===

* contains a particular object.
* This also supports, pointer comparion and strings as lightweight pointers
*/
function contains(compareTo: Array, object: any): boolean {
Copy link
Contributor

@acinader acinader Oct 3, 2017

Choose a reason for hiding this comment

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

The names of the parameters are confusing to me. particularly compareTo.

haystack, needle?

@codecov
Copy link

codecov bot commented Oct 3, 2017

Codecov Report

Merging #4231 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4231      +/-   ##
==========================================
- Coverage   92.24%   92.22%   -0.02%     
==========================================
  Files         116      116              
  Lines        8098     8107       +9     
==========================================
+ Hits         7470     7477       +7     
- Misses        628      630       +2
Impacted Files Coverage Δ
src/LiveQuery/QueryTools.js 93.97% <100%> (+0.34%) ⬆️
src/RestWrite.js 93.16% <0%> (-0.56%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.62% <0%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23bffc8...ea62945. Read the comment docs.

@flovilmart
Copy link
Contributor Author

Thanks for the quick review @acinader !

acinader
acinader previously approved these changes Oct 3, 2017
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

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

lgtm. I'm offering an alternative intro comment for your contain function, for your consideration.

@@ -90,6 +90,30 @@ function queryHash(query) {
}

/**
* contains -- Determines whether a constraint in the form of a list
Copy link
Contributor

Choose a reason for hiding this comment

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

how about:

Determines if an object is contained in a list with special handling for Parse pointers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LOVE it!

@flovilmart
Copy link
Contributor Author

seems that eslint don't catch issue when doing typeof undefinedVariable 

@@ -99,8 +99,7 @@ function contains(haystack: Array, needle: any): boolean {
if (typeof ptr === 'string' && ptr === needle.objectId) {
return true;
}
if (typeof object !== 'undefined' &&
ptr.className === needle.className &&
if (ptr.className === needle.className &&
Copy link
Contributor

Choose a reason for hiding this comment

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

that seems good, you've already validated that needle is not undefined in the conatining if.

Copy link
Contributor

Choose a reason for hiding this comment

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

not really sure if we should be forcing

typeof needle !== 'undefined'

over

if(needle)

I use the second form in my code. Obviously could be an issue in the case of boolean but i just ignore that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obviously could be an issue in the case of boolean but i just ignore that...

if it's a boolean, we'll go to the 'indexOf' case which is correct :)

Copy link
Contributor

Choose a reason for hiding this comment

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

yup, i was musing out loud more generally about if we should enforce a more formal test than just if(foo) without advocating that we switch to it.... :). so safe to ignore me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all those bottom values in JS makes it difficult to make it consistent :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants