"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _EventEmitter2 = _interopRequireDefault(require("./EventEmitter")); var _CoreManager = _interopRequireDefault(require("./CoreManager")); /* * Copyright (c) 2015-present, Parse, LLC. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * */ /** * Creates a new LiveQuery Subscription. * Extends events.EventEmitter * cloud functions. * * *
Open Event - When you call query.subscribe(), we send a subscribe request to * the LiveQuery server, when we get the confirmation from the LiveQuery server, * this event will be emitted. When the client loses WebSocket connection to the * LiveQuery server, we will try to auto reconnect the LiveQuery server. If we * reconnect the LiveQuery server and successfully resubscribe the ParseQuery, * you'll also get this event. * *
* subscription.on('open', () => { * * });* *
Create Event - When a new ParseObject is created and it fulfills the ParseQuery you subscribe, * you'll get this event. The object is the ParseObject which is created. * *
* subscription.on('create', (object) => { * * });* *
Update Event - When an existing ParseObject (original) which fulfills the ParseQuery you subscribe * is updated (The ParseObject fulfills the ParseQuery before and after changes), * you'll get this event. The object is the ParseObject which is updated. * Its content is the latest value of the ParseObject. * * Parse-Server 3.1.3+ Required for original object parameter * *
* subscription.on('update', (object, original) => { * * });* *
Enter Event - When an existing ParseObject's (original) old value doesn't fulfill the ParseQuery * but its new value fulfills the ParseQuery, you'll get this event. The object is the * ParseObject which enters the ParseQuery. Its content is the latest value of the ParseObject. * * Parse-Server 3.1.3+ Required for original object parameter * *
* subscription.on('enter', (object, original) => { * * });* * *
Update Event - When an existing ParseObject's old value fulfills the ParseQuery but its new value * doesn't fulfill the ParseQuery, you'll get this event. The object is the ParseObject * which leaves the ParseQuery. Its content is the latest value of the ParseObject. * *
* subscription.on('leave', (object) => { * * });* * *
Delete Event - When an existing ParseObject which fulfills the ParseQuery is deleted, you'll * get this event. The object is the ParseObject which is deleted. * *
* subscription.on('delete', (object) => { * * });* * *
Close Event - When the client loses the WebSocket connection to the LiveQuery * server and we stop receiving events, you'll get this event. * *
* subscription.on('close', () => { * * });* * @alias Parse.LiveQuerySubscription */ var Subscription = /*#__PURE__*/ function (_EventEmitter) { (0, _inherits2.default)(Subscription, _EventEmitter); /* * @param {string} id - subscription id * @param {string} query - query to subscribe to * @param {string} sessionToken - optional session token */ function Subscription(id, query, sessionToken) { var _this; (0, _classCallCheck2.default)(this, Subscription); _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Subscription).call(this)); _this.id = id; _this.query = query; _this.sessionToken = sessionToken; // adding listener so process does not crash // best practice is for developer to register their own listener _this.on('error', function () {}); return _this; } /** * Close the subscription */ (0, _createClass2.default)(Subscription, [{ key: "unsubscribe", value: function () /*: Promise*/ { var _this2 = this; return _CoreManager.default.getLiveQueryController().getDefaultLiveQueryClient().then(function (liveQueryClient) { liveQueryClient.unsubscribe(_this2); _this2.emit('close'); }); } }]); return Subscription; }(_EventEmitter2.default); var _default = Subscription; exports.default = _default;