-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Conversation
spec/QueryTools.spec.js
Outdated
@@ -495,4 +495,79 @@ describe('matchesQuery', function() { | |||
expect(matchesQuery(message, q)).toBe(false); | |||
|
|||
}); | |||
|
|||
function pointer(className, objectId) { | |||
return {__type: 'Pointer', className, objectId }; |
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.
add whitespace between { __
src/LiveQuery/QueryTools.js
Outdated
@@ -90,6 +90,28 @@ function queryHash(query) { | |||
} | |||
|
|||
/** | |||
* contains -- Determines wether a constaint in for form of a list |
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.
"whether" and "constraint" are misspelled. I haven't read the code yet, but I really can't understand this comment.
src/LiveQuery/QueryTools.js
Outdated
@@ -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 |
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.
"comparison" is misspelled.
src/LiveQuery/QueryTools.js
Outdated
if (object.__type && object.__type === 'Pointer') { | ||
for (const i in compareTo) { | ||
const ptr = compareTo[i]; | ||
if (typeof ptr == 'string' && ptr === object.objectId) { |
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.
===
src/LiveQuery/QueryTools.js
Outdated
* contains a particular object. | ||
* This also supports, pointer comparion and strings as lightweight pointers | ||
*/ | ||
function contains(compareTo: Array, object: any): boolean { |
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.
The names of the parameters are confusing to me. particularly compareTo.
haystack, needle?
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Thanks for the quick review @acinader ! |
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.
lgtm. I'm offering an alternative intro comment for your contain function, for your consideration.
src/LiveQuery/QueryTools.js
Outdated
@@ -90,6 +90,30 @@ function queryHash(query) { | |||
} | |||
|
|||
/** | |||
* contains -- Determines whether a constraint in the form of a list |
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.
how about:
Determines if an object is contained in a list with special handling for Parse pointers.
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.
LOVE it!
seems that eslint don't catch issue when doing |
src/LiveQuery/QueryTools.js
Outdated
@@ -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 && |
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.
that seems good, you've already validated that needle is not undefined in the conatining if.
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.
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...
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.
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 :)
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.
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.
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.
all those bottom values in JS makes it difficult to make it consistent :/
No description provided.