Skip to content

Commit a2947a8

Browse files
authored
Update cloud-code.md
1 parent 3348014 commit a2947a8

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

_includes/cloudcode/cloud-code.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -654,26 +654,39 @@ Parse.Cloud.afterLiveQueryEvent('MyObject', request => {
654654
original.set('name', 'yolo');
655655
});
656656

657+
// Prevent LiveQuery trigger unless 'foo' is modified
658+
Parse.Cloud.afterLiveQueryEvent('MyObject', (request) => {
659+
const object = request.object;
660+
const original = request.original;
661+
if (!original) {
662+
return;
663+
}
664+
if (object.get('foo') != original.get('foo')) {
665+
req.sendEvent = false;
666+
}
667+
});
668+
657669
// Including an object on LiveQuery event, on update only.
658-
Parse.Cloud.afterLiveQueryEvent('MyObject', async request => {
659-
if (request.event != 'update) {
670+
Parse.Cloud.afterLiveQueryEvent('MyObject', async (request) => {
671+
if (request.event != "update") {
660672
request.sendEvent = false;
661673
return;
662674
}
663675
const object = request.object;
664-
const pointer = object.get('child');
676+
const pointer = object.get("child");
665677
await pointer.fetch();
666678
});
667679

668-
// Prevent LiveQuery trigger unless 'foo' is modified
669-
Parse.Cloud.afterLiveQueryEvent('MyObject', request => {
670-
const object = request.object;
671-
const original = request.original;
672-
if (!original) {
680+
//Extend matchesQuery functionality to LiveQuery
681+
Parse.Cloud.afterLiveQueryEvent('MyObject', async (request) => {
682+
if (req.event != "Create") {
673683
return;
674684
}
675-
if (object.get('foo') != original.get('foo')) {
676-
req.sendEvent = false;
685+
const query = request.object.relation('children').query();
686+
query.equalTo('foo','bart');
687+
const first = await query.first();
688+
if (!first) {
689+
request.sendEvent = false;
677690
}
678691
});
679692
```

0 commit comments

Comments
 (0)