@@ -4,7 +4,12 @@ const { inherits } = require('./utils');
44const { request } = require ( './request' ) ;
55
66module . exports = ( AV ) => {
7- const LiveQuery = AV . LiveQuery = inherits ( EventEmitter , {
7+ /**
8+ * @class
9+ * A LiveQuery, created by {@link AV.Query#subscribe} is an EventEmitter notifies changes of the Query.
10+ * @since 3.0.0
11+ */
12+ AV . LiveQuery = inherits ( EventEmitter , /** @lends AV.LiveQuery.prototype */ {
813 constructor ( id , client ) {
914 EventEmitter . apply ( this ) ;
1015 this . id = id ;
@@ -24,12 +29,43 @@ module.exports = (AV) => {
2429 __type : object . className === '_File' ? 'File' : 'Object' ,
2530 } , object ) ) ;
2631 if ( updatedKeys ) {
32+ /**
33+ * An existing AV.Object which fulfills the Query you subscribe is updated.
34+ * @event AV.LiveQuery#update
35+ * @param {AV.Object|AV.File } target updated object
36+ * @param {String[] } updatedKeys updated keys
37+ */
2738 this . emit ( op , target , updatedKeys ) ;
2839 } else {
40+ /**
41+ * A new AV.Object which fulfills the Query you subscribe is created.
42+ * @event AV.LiveQuery#create
43+ * @param {AV.Object|AV.File } target updated object
44+ */
45+ /**
46+ * An existing AV.Object which fulfills the Query you subscribe is deleted.
47+ * @event AV.LiveQuery#delete
48+ * @param {AV.Object|AV.File } target updated object
49+ */
50+ /**
51+ * An existing AV.Object which doesn't fulfill the Query is updated and now it fulfills the Query.
52+ * @event AV.LiveQuery#enter
53+ * @param {AV.Object|AV.File } target updated object
54+ */
55+ /**
56+ * An existing AV.Object which fulfills the Query is updated and now it doesn't fulfill the Query.
57+ * @event AV.LiveQuery#leave
58+ * @param {AV.Object|AV.File } target updated object
59+ */
2960 this . emit ( op , target ) ;
3061 }
3162 } ) ;
3263 } ,
64+ /**
65+ * unsubscribe the query
66+ *
67+ * @return {Promise }
68+ */
3369 unsubscribe ( ) {
3470 this . _client . deregister ( this ) ;
3571 return request ( {
@@ -64,7 +100,7 @@ module.exports = (AV) => {
64100 } ) . then ( ( {
65101 query_id : queryId ,
66102 } ) => AV . _config . realtime . createLiveQueryClient ( subscriptionId )
67- . then ( liveQueryClient => new LiveQuery ( queryId , liveQueryClient ) )
103+ . then ( liveQueryClient => new AV . LiveQuery ( queryId , liveQueryClient ) )
68104 )
69105 ) ;
70106 } ,
0 commit comments