Skip to content

fix: Parse ViewModels properties always dispatch to the main queue #260

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 1 commit into from
Oct 17, 2021
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

### main

[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.1...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/2.0.2...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

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

__Improvements__
- Add static methods for accessing encoders/decoder so developers do not have to create instances to access ([#259](https://github.com/parse-community/Parse-Swift/pull/259)), thanks to [Corey Baker](https://github.com/cbaker6).

__Fixes__
- Parse ViewModels always dispatch to the main queue when updating published properties. This prevents possible issues when background async calls update properties used for views ([#260](https://github.com/parse-community/Parse-Swift/pull/260)), thanks to [Corey Baker](https://github.com/cbaker6).

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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/parse-community/Parse-Swift", from: "1.10.1"),
.package(url: "https://github.com/parse-community/Parse-Swift", from: "2.0.2"),
]
)
```
Expand Down
12 changes: 9 additions & 3 deletions Sources/ParseSwift/LiveQuery/Subscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ open class Subscription<T: ParseObject>: QueryViewModel<T>, QuerySubscribable {
if newValue != nil {
subscribed = nil
unsubscribed = nil
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand All @@ -81,7 +83,9 @@ open class Subscription<T: ParseObject>: QueryViewModel<T>, QuerySubscribable {
if newValue != nil {
unsubscribed = nil
event = nil
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand All @@ -92,7 +96,9 @@ open class Subscription<T: ParseObject>: QueryViewModel<T>, QuerySubscribable {
if newValue != nil {
subscribed = nil
event = nil
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "2.0.1"
static let version = "2.0.2"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
8 changes: 6 additions & 2 deletions Sources/ParseSwift/Types/CloudViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ open class CloudViewModel<T: ParseCloud>: CloudObservable {
willSet {
if newValue != nil {
self.error = nil
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand All @@ -32,7 +34,9 @@ open class CloudViewModel<T: ParseCloud>: CloudObservable {
willSet {
if newValue != nil {
self.results = nil
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions Sources/ParseSwift/Types/QueryViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
open var results = [Object]() {
willSet {
count = newValue.count
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}

Expand All @@ -31,7 +33,9 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
willSet {
error = nil
if newValue != results.count {
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand All @@ -42,7 +46,9 @@ open class QueryViewModel<T: ParseObject>: QueryObservable {
if newValue != nil {
results.removeAll()
count = results.count
objectWillChange.send()
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
}
}
Expand Down