Skip to content
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

Use ParseLiveQuery Subscription as a SwiftUI view model #65

Merged
merged 7 commits into from
Jan 25, 2021
Merged

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Jan 24, 2021

Adds support to use a ParseLiveQuery subscription as a VM. Once more people start using the SDK, this will probably be a highly sought after feature.

ParseLiveQuery and its ability to subscribe to events is suited to be a great candidate for SwiftUI updates or serve as a publisher of data in general to allow updates to views. The original Subscription, now renamed to SubscriptionCallback was a spin on the original Subscription in ParseLiveQuery-iOS. The new Subscription and the original essentially behave in a similar manner except the original was designed before property wrappers and before SwiftUI.

The change allows devs a different way from the objective-c SDK when accessing Parse data.

  1. Use a traditional query find (pull) to get the original objects to display in your SwiftUI view.
  2. Use a ParseLiveQuery Subscription as a view model (VM) for any subsequent updates in your SwiftUI view.

This update is "slightly" breaking as the original Subscription has been renamed to SubscriptionCallback. Both still have properties accessible directly from any Query. For example if you have var query = GameScore.query("score" > 9). Then:

  1. Subscription - let subscription = query.subscribe
  2. SubscriptionCallback - let subscription = query.subscribeCallback

@codecov
Copy link

codecov bot commented Jan 24, 2021

Codecov Report

Merging #65 (986920c) into main (80802c5) will increase coverage by 0.15%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #65      +/-   ##
==========================================
+ Coverage   77.95%   78.11%   +0.15%     
==========================================
  Files          51       51              
  Lines        4578     4614      +36     
==========================================
+ Hits         3569     3604      +35     
- Misses       1009     1010       +1     
Impacted Files Coverage Δ
Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift 74.61% <0.00%> (-0.13%) ⬇️
Sources/ParseSwift/LiveQuery/Subscription.swift 75.94% <94.11%> (+12.68%) ⬆️
Sources/ParseSwift/Objects/ParseUser.swift 75.04% <0.00%> (+0.17%) ⬆️
Sources/ParseSwift/Objects/ParseObject.swift 76.31% <0.00%> (+0.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80802c5...986920c. Read the comment docs.

@cbaker6
Copy link
Contributor Author

cbaker6 commented Jan 24, 2021

@TomWFox I added docs to the "new" Subscription. Can you review them?

@cbaker6 cbaker6 requested a review from TomWFox January 24, 2021 20:08
Copy link
Contributor

@TomWFox TomWFox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one . 😅

LGTM 🚀

Sources/ParseSwift/LiveQuery/ParseLiveQuery.swift Outdated Show resolved Hide resolved
Co-authored-by: Tom Fox <13188249+TomWFox@users.noreply.github.com>
@cbaker6 cbaker6 merged commit 39f20d2 into main Jan 25, 2021
@cbaker6 cbaker6 deleted the liveQuery branch January 25, 2021 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants