Skip to content

Commit 1e2d713

Browse files
authored
fix: Switch LiveQuery listen to watch (#48)
1 parent 8da4178 commit 1e2d713

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
__New features__
1212

13-
* Adds the the ability to listen to particular keys with LiveQueries. Requires Parse-Server 6.0.0 ([#46](https://github.com/netreconlab/Parse-Swift/pull/46)), thanks to [Corey Baker](https://github.com/cbaker6).
13+
* Adds the the ability to watch particular keys with LiveQueries. Requires Parse-Server 6.0.0 ([#47](https://github.com/netreconlab/Parse-Swift/pull/47)), thanks to [Corey Baker](https://github.com/cbaker6).
1414

1515
* (Breaking Change) Added a new ParseHealth.Status enum to support Parse Server.
1616
Developers can access the new status values (Status.initialized, Status.starting)

Sources/ParseSwift/LiveQuery/Messages.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct SubscribeQuery: Encodable {
4949
let className: String
5050
let `where`: QueryWhere
5151
let fields: [String]?
52-
let listen: [String]?
52+
let watch: [String]?
5353
}
5454

5555
struct SubscribeMessage<T: ParseObject>: LiveQueryable, Encodable {
@@ -71,7 +71,7 @@ struct SubscribeMessage<T: ParseObject>: LiveQueryable, Encodable {
7171
self.query = SubscribeQuery(className: query.className,
7272
where: query.where,
7373
fields: query.fields?.sorted() ?? query.keys?.sorted(),
74-
listen: query.listen?.sorted())
74+
watch: query.watch?.sorted())
7575
}
7676
self.sessionToken = BaseParseUser.currentContainer?.sessionToken
7777
}

Sources/ParseSwift/Types/Query.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct Query<T>: ParseTypeable where T: ParseObject {
3131
internal var distinct: String?
3232
internal var pipeline: [[String: AnyCodable]]?
3333
internal var fields: Set<String>?
34-
internal var listen: Set<String>?
34+
internal var watch: Set<String>?
3535
var endpoint: API.Endpoint {
3636
.objects(className: T.className)
3737
}
@@ -416,11 +416,11 @@ public struct Query<T>: ParseTypeable where T: ParseObject {
416416
}
417417

418418
/**
419-
A variadic list of keys to listen to mutations on when using `ParseLiveQuery`.
419+
A variadic list of keys to watch mutations on when using `ParseLiveQuery`.
420420

421-
Suppose the `ParseObject` Player contains three fields name, id and age.
421+
Suppose the `ParseObject` Player contains three fields: name, position, and age.
422422
If you are only interested in the change of the **name** key, you can set
423-
`query.listen` to **name**. In this situation, when the change of a
423+
`query.watch` to **name**. In this situation, when the change of a
424424
Player `ParseObject` fulfills the subscription and the **name** key is updated,
425425
only the name field will be sent to the clients instead of the full Player `ParseObject`.
426426
If this is called multiple times, then all of the keys specified in each of the calls will be received.
@@ -429,16 +429,16 @@ public struct Query<T>: ParseTypeable where T: ParseObject {
429429
- parameter keys: A variadic list of fields to receive back instead of the whole `ParseObject`.
430430
- returns: The mutated instance of query for easy chaining.
431431
*/
432-
public func listen(_ keys: String...) -> Query<T> {
433-
self.listen(keys)
432+
public func watch(_ keys: String...) -> Query<T> {
433+
self.watch(keys)
434434
}
435435

436436
/**
437-
A list of keys to listen to mutations on when using `ParseLiveQuery`.
437+
A list of keys to watch mutations on when using `ParseLiveQuery`.
438438

439-
Suppose the `ParseObject` Player contains three fields name, id and age.
439+
Suppose the `ParseObject` Player contains three fields: name, position, and age.
440440
If you are only interested in the change of the **name** key, you can set
441-
`query.listen` to **name**. In this situation, when the change of a
441+
`query.watch` to **name**. In this situation, when the change of a
442442
Player `ParseObject` fulfills the subscription and the **name** key is updated,
443443
only the name field will be sent to the clients instead of the full Player `ParseObject`.
444444
If this is called multiple times, then all of the keys specified in each of the calls will be received.
@@ -447,12 +447,12 @@ public struct Query<T>: ParseTypeable where T: ParseObject {
447447
- parameter keys: An array of keys to lisen to instead of the whole `ParseObject`.
448448
- returns: The mutated instance of query for easy chaining.
449449
*/
450-
public func listen(_ keys: [String]) -> Query<T> {
450+
public func watch(_ keys: [String]) -> Query<T> {
451451
var mutableQuery = self
452-
if mutableQuery.listen != nil {
453-
mutableQuery.listen = mutableQuery.listen?.union(keys)
452+
if mutableQuery.watch != nil {
453+
mutableQuery.watch = mutableQuery.watch?.union(keys)
454454
} else {
455-
mutableQuery.listen = Set(keys)
455+
mutableQuery.watch = Set(keys)
456456
}
457457
return mutableQuery
458458
}

Tests/ParseSwiftTests/ParseLiveQueryTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,9 @@ class ParseLiveQueryTests: XCTestCase {
263263

264264
func testSubscribeMessageListenEncoding() throws {
265265
// swiftlint:disable:next line_length
266-
let expected = "{\"op\":\"subscribe\",\"query\":{\"className\":\"GameScore\",\"listen\":[\"hello\",\"points\"],\"where\":{\"points\":{\"$gt\":9}}},\"requestId\":1}"
266+
let expected = "{\"op\":\"subscribe\",\"query\":{\"className\":\"GameScore\",\"watch\":[\"hello\",\"points\"],\"where\":{\"points\":{\"$gt\":9}}},\"requestId\":1}"
267267
let query = GameScore.query("points" > 9)
268-
.listen(["hello", "points"])
268+
.watch(["hello", "points"])
269269
let message = SubscribeMessage(operation: .subscribe,
270270
requestId: RequestId(value: 1),
271271
query: query,
@@ -277,23 +277,23 @@ class ParseLiveQueryTests: XCTestCase {
277277
}
278278

279279
func testListenKeys() throws {
280-
var query = GameScore.query.listen(["yolo"])
281-
XCTAssertEqual(query.listen?.count, 1)
282-
XCTAssertEqual(query.listen?.first, "yolo")
280+
var query = GameScore.query.watch(["yolo"])
281+
XCTAssertEqual(query.watch?.count, 1)
282+
XCTAssertEqual(query.watch?.first, "yolo")
283283

284-
query = query.listen(["hello", "wow"])
285-
XCTAssertEqual(query.listen?.count, 3)
286-
XCTAssertEqual(query.listen, ["yolo", "hello", "wow"])
284+
query = query.watch(["hello", "wow"])
285+
XCTAssertEqual(query.watch?.count, 3)
286+
XCTAssertEqual(query.watch, ["yolo", "hello", "wow"])
287287
}
288288

289289
func testListenKeysVariadic() throws {
290-
var query = GameScore.query.listen("yolo")
291-
XCTAssertEqual(query.listen?.count, 1)
292-
XCTAssertEqual(query.listen?.first, "yolo")
290+
var query = GameScore.query.watch("yolo")
291+
XCTAssertEqual(query.watch?.count, 1)
292+
XCTAssertEqual(query.watch?.first, "yolo")
293293

294-
query = query.listen("hello", "wow")
295-
XCTAssertEqual(query.listen?.count, 3)
296-
XCTAssertEqual(query.listen, ["yolo", "hello", "wow"])
294+
query = query.watch("hello", "wow")
295+
XCTAssertEqual(query.watch?.count, 3)
296+
XCTAssertEqual(query.watch, ["yolo", "hello", "wow"])
297297
}
298298

299299
func testRedirectResponseDecoding() throws {

0 commit comments

Comments
 (0)