Skip to content

Commit

Permalink
fix: Parse ViewModels properties always dispatch to the main queue (#260
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cbaker6 authored Oct 17, 2021
1 parent 3934a45 commit 2bda2fd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
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

0 comments on commit 2bda2fd

Please sign in to comment.