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

feat: add revertKeyPath() and revertObject() methods to ParseObject #402

Merged
merged 3 commits into from Sep 4, 2022

Conversation

cbaker6
Copy link
Contributor

@cbaker6 cbaker6 commented Sep 4, 2022

New Pull Request Checklist

Issue Description

After a developer begins mutating/updating a ParseObject that already has an objectId via mergeable or some other method that allows the developer to save the ParseObject using the Parse Servers quirky patch. The only way to revert a specific KeyPath back to its original value is by setting it based on a local stored version or remembering what that value was.

Related issue: #n/a

Approach

Leverage the originalData property to allow developers to revert specific KeyPath's or the whole ParseObject.

Example usage:

/* 
Assuming `score` is a GameScore `ParseObject` which was already saved and has the following properties:
- objectId = "yolo"
- name = "Frazier"
- points = 19
- ...
*/

// Reverting the whole object
var mutableScore = score.mergeable
mutableScore.points = 50
mutableScore.player = "Ali"         
mutableScore = try mutableScore.revertObject()
print(mutableScore == score) // true

// Reverting a specific KeyPath
var mutableScore2 = score.mergeable
mutableScore2.points = 50
mutableScore2.player = "Ali"         
mutableScore2 = try mutableScore2.revertKeyPath(\.player)
print(mutableScore2 == score) // false
print(mutableScore2 == mutableScore) // false
print(mutableScore2.player == score.player) // true
print(mutableScore2.player == mutableScore.player) // true

TODOs before merging

  • Add tests
  • Add entry to changelog
  • Add changes to documentation (guides, repository pages, in-code descriptions)

@parse-github-assistant
Copy link

parse-github-assistant bot commented Sep 4, 2022

Thanks for opening this pull request!

  • 🎉 We are excited about your hands-on contribution!

@codecov
Copy link

codecov bot commented Sep 4, 2022

Codecov Report

Merging #402 (b9552e1) into main (106f97d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #402   +/-   ##
=======================================
  Coverage   89.64%   89.65%           
=======================================
  Files         158      158           
  Lines       15081    15113   +32     
=======================================
+ Hits        13519    13549   +30     
- Misses       1562     1564    +2     
Impacted Files Coverage Δ
Sources/ParseSwift/Objects/ParseObject.swift 87.73% <100.00%> (+0.28%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@cbaker6 cbaker6 merged commit 9dac227 into parse-community:main Sep 4, 2022
@cbaker6 cbaker6 deleted the revertMutatedObject branch September 4, 2022 16:33
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

1 participant