Skip to content

Commit 656d673

Browse files
authored
feat: Add support for $eq query constraint in LiveQuery (#8614)
1 parent b01d4f0 commit 656d673

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Diff for: spec/QueryTools.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,35 @@ describe('matchesQuery', function () {
125125
expect(matchesQuery(obj, q)).toBe(false);
126126
});
127127

128+
it('matches queries with eq constraint', function () {
129+
const obj = {
130+
objectId: 'Person2',
131+
score: 12,
132+
name: 'Tom',
133+
};
134+
135+
const q1 = {
136+
objectId: {
137+
$eq: 'Person2',
138+
},
139+
};
140+
141+
const q2 = {
142+
score: {
143+
$eq: 12,
144+
},
145+
};
146+
147+
const q3 = {
148+
name: {
149+
$eq: 'Tom',
150+
},
151+
};
152+
expect(matchesQuery(obj, q1)).toBe(true);
153+
expect(matchesQuery(obj, q2)).toBe(true);
154+
expect(matchesQuery(obj, q3)).toBe(true);
155+
});
156+
128157
it('matches on equality queries', function () {
129158
const day = new Date();
130159
const location = new Parse.GeoPoint({

Diff for: src/LiveQuery/QueryTools.js

+5
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ function matchesKeyConstraints(object, key, constraints) {
247247
return false;
248248
}
249249
break;
250+
case '$eq':
251+
if (!equalObjects(object[key], compareTo)) {
252+
return false;
253+
}
254+
break;
250255
case '$ne':
251256
if (equalObjects(object[key], compareTo)) {
252257
return false;

0 commit comments

Comments
 (0)