@@ -223,6 +223,7 @@ Not attempting to open ParseLiveQuery socket anymore
223
223
}
224
224
}
225
225
226
+ // MARK: Client Intents
226
227
extension ParseLiveQuery {
227
228
228
229
/// Current LiveQuery client.
@@ -265,20 +266,29 @@ extension ParseLiveQuery {
265
266
}
266
267
}
267
268
269
+ /// The default `ParseLiveQuery` client for all LiveQuery connections.
270
+ class public var defaultClient : ParseLiveQuery ? {
271
+ Self . client
272
+ }
273
+
268
274
/// Set a specific ParseLiveQuery client to be the default for all `ParseLiveQuery` connections.
269
275
/// - parameter client: The client to set as the default.
270
276
class public func setDefault( _ client: ParseLiveQuery ) {
271
- ParseLiveQuery . client = nil
272
- ParseLiveQuery . client = client
277
+ Self . client = nil
278
+ Self . client = client
273
279
}
274
280
275
281
/// Get the default `ParseLiveQuery` client for all LiveQuery connections.
282
+ /// - returns: The default `ParseLiveQuery` client.
283
+ /// - warning: This will be deprecated in ParseSwift 5.0.0 in favor of `defaultClient`.
276
284
class public func getDefault( ) -> ParseLiveQuery ? {
277
- ParseLiveQuery . client
285
+ Self . defaultClient
278
286
}
279
287
280
288
/// Check if a query has an active subscription on this `ParseLiveQuery` client.
281
289
/// - parameter query: Query to verify.
290
+ /// - returns: **true** if subscribed. **false** otherwise.
291
+ /// - throws: An error of type `ParseError`.
282
292
public func isSubscribed< T: ParseObject > ( _ query: Query < T > ) throws -> Bool {
283
293
let queryData = try ParseCoding . jsonEncoder ( ) . encode ( query)
284
294
return subscriptions. contains ( where: { ( _, value) -> Bool in
@@ -292,6 +302,8 @@ extension ParseLiveQuery {
292
302
293
303
/// Check if a query has a pending subscription on this `ParseLiveQuery` client.
294
304
/// - parameter query: Query to verify.
305
+ /// - returns: **true** if query is a pending subscription. **false** otherwise.
306
+ /// - throws: An error of type `ParseError`.
295
307
public func isPendingSubscription< T: ParseObject > ( _ query: Query < T > ) throws -> Bool {
296
308
let queryData = try ParseCoding . jsonEncoder ( ) . encode ( query)
297
309
return pendingSubscriptions. contains ( where: { ( _, value) -> Bool in
@@ -305,6 +317,7 @@ extension ParseLiveQuery {
305
317
306
318
/// Remove a pending subscription on this `ParseLiveQuery` client.
307
319
/// - parameter query: Query to remove.
320
+ /// - throws: An error of type `ParseError`.
308
321
public func removePendingSubscription< T: ParseObject > ( _ query: Query < T > ) throws {
309
322
let queryData = try ParseCoding . jsonEncoder ( ) . encode ( query)
310
323
pendingSubscriptions. removeAll ( where: { ( _, value) -> Bool in
@@ -851,7 +864,8 @@ public extension Query {
851
864
as the subscription can be used as a SwiftUI publisher. Meaning it can serve
852
865
indepedently as a ViewModel in MVVM.
853
866
- parameter client: A specific client.
854
- - returns: The subscription that has just been registered
867
+ - returns: The subscription that has just been registered.
868
+ - throws: An error of type `ParseError`.
855
869
*/
856
870
func subscribe( _ client: ParseLiveQuery ) throws -> Subscription < ResultType > {
857
871
try client. subscribe ( Subscription ( query: self ) )
@@ -862,6 +876,7 @@ public extension Query {
862
876
Registers a query for live updates, using a custom subscription handler.
863
877
- parameter handler: A custom subscription handler.
864
878
- returns: Your subscription handler, for easy chaining.
879
+ - throws: An error of type `ParseError`.
865
880
*/
866
881
static func subscribe< T: QuerySubscribable > ( _ handler: T ) throws -> T {
867
882
if let client = ParseLiveQuery . client {
@@ -876,6 +891,7 @@ public extension Query {
876
891
- parameter handler: A custom subscription handler.
877
892
- parameter client: A specific client.
878
893
- returns: Your subscription handler, for easy chaining.
894
+ - throws: An error of type `ParseError`.
879
895
*/
880
896
static func subscribe< T: QuerySubscribable > ( _ handler: T , client: ParseLiveQuery ) throws -> T {
881
897
try client. subscribe ( handler)
@@ -894,6 +910,7 @@ public extension Query {
894
910
and a specific `ParseLiveQuery` client.
895
911
- parameter client: A specific client.
896
912
- returns: The subscription that has just been registered.
913
+ - throws: An error of type `ParseError`.
897
914
*/
898
915
func subscribeCallback( _ client: ParseLiveQuery ) throws -> SubscriptionCallback < ResultType > {
899
916
try client. subscribe ( SubscriptionCallback ( query: self ) )
@@ -905,6 +922,7 @@ public extension Query {
905
922
/**
906
923
Unsubscribes all current subscriptions for a given query on the default
907
924
`ParseLiveQuery` client.
925
+ - throws: An error of type `ParseError`.
908
926
*/
909
927
func unsubscribe( ) throws {
910
928
try ParseLiveQuery . client? . unsubscribe ( self )
@@ -914,6 +932,7 @@ public extension Query {
914
932
Unsubscribes all current subscriptions for a given query on a specific
915
933
`ParseLiveQuery` client.
916
934
- parameter client: A specific client.
935
+ - throws: An error of type `ParseError`.
917
936
*/
918
937
func unsubscribe( client: ParseLiveQuery ) throws {
919
938
try client. unsubscribe ( self )
@@ -923,6 +942,7 @@ public extension Query {
923
942
Unsubscribes from a specific query-handler on the default
924
943
`ParseLiveQuery` client.
925
944
- parameter handler: The specific handler to unsubscribe from.
945
+ - throws: An error of type `ParseError`.
926
946
*/
927
947
func unsubscribe< T: QuerySubscribable > ( _ handler: T ) throws {
928
948
try ParseLiveQuery . client? . unsubscribe ( handler)
@@ -933,6 +953,7 @@ public extension Query {
933
953
`ParseLiveQuery` client.
934
954
- parameter handler: The specific handler to unsubscribe from.
935
955
- parameter client: A specific client.
956
+ - throws: An error of type `ParseError`.
936
957
*/
937
958
func unsubscribe< T: QuerySubscribable > ( _ handler: T , client: ParseLiveQuery ) throws {
938
959
try client. unsubscribe ( handler)
@@ -945,6 +966,7 @@ public extension Query {
945
966
Updates an existing subscription with a new query on the default `ParseLiveQuery` client.
946
967
Upon completing the registration, the subscribe handler will be called with the new query.
947
968
- parameter handler: The specific handler to update.
969
+ - throws: An error of type `ParseError`.
948
970
*/
949
971
func update< T: QuerySubscribable > ( _ handler: T ) throws {
950
972
try ParseLiveQuery . client? . update ( handler)
@@ -955,6 +977,7 @@ public extension Query {
955
977
Upon completing the registration, the subscribe handler will be called with the new query.
956
978
- parameter handler: The specific handler to update.
957
979
- parameter client: A specific client.
980
+ - throws: An error of type `ParseError`.
958
981
*/
959
982
func update< T: QuerySubscribable > ( _ handler: T , client: ParseLiveQuery ) throws {
960
983
try client. update ( handler)
0 commit comments