Skip to content

Send only changed properties to cloud by default when updating object #401

Closed
@mtrezza

Description

@mtrezza

New Feature / Enhancement Checklist

Current Limitation

The Parse Swift SDK requires additional code overhead and developer considerations when updating objects. Specifically, to send only changed properties to the server, the SDK requires the developer to create an object clone from ParseObject.mergeable and override an internal method ParseObject.merge . The same behavior is achieved by other Parse SDKs without these efforts.

The disadvantages are:

  • Developer needs to manually maintain custom properties in the overridden ParseObject.merge method. For example, if a new custom property is added to the object but not to the internal method, it creates data inconsistencies that may lead to bugs that are difficult to track down.
  • Adds code complexity for what is supposed to be one of the simplest operations - updating an object.

Feature / Enhancement Description

The Parse Swift SDK should send only the changed properties to the server by default. Without requiring the developer to override an internal method of ParseObject and without having to clone the object from ParseObject.mergeable.

Example Use Case

The following examples compare how to update a saved object in the Parse ObjC SDK vs. the Parse Swift SDK.

// Parse ObjC SDK
PFObject *obj = [PFObject objectWithClassName:@"Example"];
obj[@"key"] = @"value1";
[obj save];
obj[@"key"] = @"value2";
[obj save];

// Parse Swift SDK
struct Example: ParseObject {
  var objectId: String?
  var createdAt: Date?
  var updatedAt: Date?
  var ACL: ParseACL?
  var originalData: Data? 
  var key: String?

  func merge(with object: Self) throws -> Self { 
    var updated = try mergeParse(with: object) 
    if updated.shouldRestoreKey(\.key, original: object) { 
      updated.key = object.key 
    }
    return updated
  }
}

let obj = Example()
obj.key = "value1"
obj.save()
var objMergable = obj.mergeable
objMergable.key = "value2"
objMergable.save()

Alternatives / Workarounds

n/a

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions