Skip to content

Make emptyObject more developer friendly #269

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

Closed
3 tasks done
vdkdamian opened this issue Oct 30, 2021 · 4 comments · Fixed by #270
Closed
3 tasks done

Make emptyObject more developer friendly #269

vdkdamian opened this issue Oct 30, 2021 · 4 comments · Fixed by #270
Labels
type:feature New feature or improvement of existing feature

Comments

@vdkdamian
Copy link
Contributor

New Feature / Enhancement Checklist

Current Limitation

Currently the developer needs to add a emptyObject to the ParseObject struct

Feature / Enhancement Description

Adding a Updatable protocol

Example Use Case

struct GameScore: ParseObject, Updatable {
    //: Those are required for Object
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?

    //: Your own properties.
    var score: Int = 0
}

var changedScore = savedScore.updatable
changedScore.score = 200
changedScore.save { result in
    switch result {
    case .success(var savedChangedScore):
        print("Succes")

    case .failure(let error):
        assertionFailure("Error saving: \(error)")
    }
}

Alternatives / Workarounds

struct GameScore: ParseObject {
    //: Those are required for Object
    var objectId: String?
    var createdAt: Date?
    var updatedAt: Date?
    var ACL: ParseACL?

    //: Your own properties.
    var score: Int = 0

    /*:
     It's recommended the developer adds the emptyObject computed property or similar.
     Gets an empty version of the respective object. This can be used when you only need to update a
     a subset of the fields of an object as oppose to updating every field of an object. Using an
     empty object and updating a subset of the fields reduces the amount of data sent between
     client and server when using `save` and `saveAll` to update objects.
    */
    var emptyObject: Self {
        var object = Self()
        object.objectId = objectId
        object.createdAt = createdAt
        return object
    }
}

3rd Party References

@parse-github-assistant
Copy link

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@cbaker6
Copy link
Contributor

cbaker6 commented Oct 30, 2021

Moving the emptyObject property to a protocol the developer can chose to add on their own will make it easier for them. Though if #263 gets to a working state, emptyObject won’t be needed anymore. We would need to think of a different name than Updatable though, maybe ParseObjectMutable and then name the property mutable. The naming change would imply that conforming to the protocol makes the ParseObject mutable for Parse purposes as opposed to general purposes.

@cbaker6 cbaker6 linked a pull request Oct 30, 2021 that will close this issue
6 tasks
@vdkdamian
Copy link
Contributor Author

@cbaker6 So should I continue adding your recommended changes? Or you think it's not needed to add this because of the solution #263 would offer?

@cbaker6
Copy link
Contributor

cbaker6 commented Oct 30, 2021

Yes, I think it’s still worthwhile. The protocol will make things easier and the 263 still needs work before it can be merged

@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants