-
Notifications
You must be signed in to change notification settings - Fork 0
/
liveQueryTest.js
63 lines (51 loc) · 1.8 KB
/
liveQueryTest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const Parse = require('parse/node');
const appConfig = {
appName: "Test App",
appId: "vYDeDN17e7M4ijmiftaPmTLBRyKh9vhpaKYCmSf3",
javascriptKey: "iIHvYViJ3BLr8I7Oqg0KECYpZk1MXBwEKy0r6p3H",
masterKey: "XHQsnf32PRhUpJW3bHwyGpFc2LDs0YH0By60UiIH",
clientKey: "ibK4sWDSKYGtmPqd9aGJcxU40WA2lb6E9jsRdgnw",
senderID: "456141054233"
};
Parse.initialize(appConfig.appId, appConfig.javascriptKey);
Parse.serverURL = 'https://testapp-annie.b4a.io';
(async () => {
const query = new Parse.Query('WatchList');
query.equalTo('isWatched', false);
let subscription = await query.subscribe();
let watchList = {};
subscription.on('open', async () => {
console.log('subscription opened');
const results = await query.find();
watchList = results.reduce((acc, cur) => ({ ...acc, [cur.id]: cur }), watchList);
console.log(JSON.stringify(watchList, null, 2));
});
subscription.on('create', (object) => {
watchList[object.id] = object;
console.log('object created');
console.log(JSON.stringify(watchList, null, 2));
});
subscription.on('update', (object) => {
console.log('object updated');
watchList[object.id] = object;
console.log(JSON.stringify(watchList, null, 2));
});
subscription.on('enter', (object) => {
console.log('object entered');
watchList[object.id] = object;
console.log(JSON.stringify(watchList, null, 2));
});
subscription.on('leave', (object) => {
console.log('object left');
delete watchList[object.id];
console.log(JSON.stringify(watchList, null, 2));
});
subscription.on('delete', (object) => {
console.log('object deleted');
delete watchList[object.id];
console.log(JSON.stringify(watchList, null, 2));
});
subscription.on('close', () => {
console.log('subscription closed');
});
})();