Skip to content

feat: allow LiveQuery client to be set using defaultClient property #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.4.0...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

__Improvements__
- Allow LiveQuery client to be set using ParseLiveQuery.defaultClient and deprecate ParseLiveQuery.setDefault(). Show usage of deprecated code as warnings during compile time and suggest changes ([#360](https://github.com/parse-community/Parse-Swift/pull/360)), thanks to [Corey Baker](https://github.com/cbaker6).

### 4.4.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.3.1...4.4.0)

Expand All @@ -30,7 +33,7 @@ __New features__
- Add variadic QueryConstraint methods for or, nor, and ([#345](https://github.com/parse-community/Parse-Swift/pull/345)), thanks to [Corey Baker](https://github.com/cbaker6).

__Improvements__
- Add clientDefault static property to ParseLiveQuery which replaces the getDefault() method. getDefault() is still avaiable, but will be deprecated in ParseSwift 5.0.0 so it is recommended to switch to clientDefault ([#342](https://github.com/parse-community/Parse-Swift/pull/342)), thanks to [Corey Baker](https://github.com/cbaker6).
- Add clientDefault static property to ParseLiveQuery which replaces the getDefault() method. getDefault() is still avaiable, but will be deprecated in ParseSwift 5.0.0 so it is recommended to switch to defaultClient ([#342](https://github.com/parse-community/Parse-Swift/pull/342)), thanks to [Corey Baker](https://github.com/cbaker6).

### 4.1.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.0.1...4.1.0)
Expand Down
18 changes: 13 additions & 5 deletions Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Not attempting to open ParseLiveQuery socket anymore
taskDelegate: self)
self.resumeTask { _ in }
if isDefault {
Self.setDefault(self)
Self.defaultClient = self
}
}

Expand Down Expand Up @@ -268,19 +268,27 @@ extension ParseLiveQuery {

/// The default `ParseLiveQuery` client for all LiveQuery connections.
class public var defaultClient: ParseLiveQuery? {
Self.client
get {
Self.client
}
set {
Self.client = nil
Self.client = newValue
}
}

/// Set a specific ParseLiveQuery client to be the default for all `ParseLiveQuery` connections.
/// - parameter client: The client to set as the default.
/// - warning: This will be removed in ParseSwift 5.0.0 in favor of `defaultClient`.
@available(*, deprecated, renamed: "defaultClient")
class public func setDefault(_ client: ParseLiveQuery) {
Self.client = nil
Self.client = client
Self.defaultClient = client
}

/// Get the default `ParseLiveQuery` client for all LiveQuery connections.
/// - returns: The default `ParseLiveQuery` client.
/// - warning: This will be deprecated in ParseSwift 5.0.0 in favor of `defaultClient`.
/// - warning: This will be removed in ParseSwift 5.0.0 in favor of `defaultClient`.
@available(*, deprecated, renamed: "defaultClient")
class public func getDefault() -> ParseLiveQuery? {
Self.defaultClient
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Objects/ParseSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public protocol ParseSession: ParseObject {
/// Information about how the session was created.
var createdWith: [String: String] { get }

/// Referrs to the `ParseInstallation` where the
/// Refers to the `ParseInstallation` where the
/// session logged in from.
var installationId: String { get }

Expand Down
3 changes: 2 additions & 1 deletion Sources/ParseSwift/Types/ParseAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public struct ParseAnalytics: ParseType, Hashable {

/// Explicitly set the time associated with a given event. If not provided the server
/// time will be used.
/// - warning: This will be deprecated in ParseSwift 5.0.0 in favor of `date`.
/// - warning: This will be removed in ParseSwift 5.0.0 in favor of `date`.
@available(*, deprecated, renamed: "date")
public var at: Date? { // swiftlint:disable:this identifier_name
get {
date
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseAnalyticsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ParseAnalyticsTests: XCTestCase {
XCTAssertEqual(command2.body?.at, date)
XCTAssertNotNil(command2.body?.dimensions)

event2.at = nil //Clear date for comparison
event2.date = nil //Clear date for comparison
let decoded = event2.debugDescription
let expected = "{\"dimensions\":{\"stop\":\"drop\"},\"name\":\"hello\"}"
XCTAssertEqual(decoded, expected)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseLiveQueryAsyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ParseLiveQueryAsyncTests: XCTestCase { // swiftlint:disable:this type_body
masterKey: "masterKey",
serverURL: url,
testing: true)
ParseLiveQuery.setDefault(try ParseLiveQuery(isDefault: true))
ParseLiveQuery.defaultClient = try ParseLiveQuery(isDefault: true)
}

override func tearDownWithError() throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/ParseSwiftTests/ParseLiveQueryCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ParseLiveQueryCombineTests: XCTestCase {
masterKey: "masterKey",
serverURL: url,
testing: true)
ParseLiveQuery.setDefault(try ParseLiveQuery(isDefault: true))
ParseLiveQuery.defaultClient = try ParseLiveQuery(isDefault: true)
}

override func tearDownWithError() throws {
Expand Down