Skip to content

Commit

Permalink
feat: add set() and auto merge updated properties with original (#406)
Browse files Browse the repository at this point in the history
* wip

* updates

* feat: add set() and auto merge updated properties with original

* updates

* update documentation and tests
  • Loading branch information
cbaker6 committed Sep 9, 2022
1 parent a94ac8c commit 8245f9e
Show file tree
Hide file tree
Showing 16 changed files with 556 additions and 143 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.10.0...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 4.11.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.10.0...4.11.0)

__New features__
- Add a set method that developers can call on their ParseObjects which automatically sends updated properties to a Parse Server and merges those updates with the original ParseObject locally. The feature removes the requirement to call mergeable and implement merge(), but comes at additional computational overhead ([#406](https://github.com/parse-community/Parse-Swift/pull/406)), thanks to [Corey Baker](https://github.com/cbaker6).

### 4.10.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.9.3...4.10.0)

Expand Down
10 changes: 0 additions & 10 deletions ParseSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,6 @@
7085DDB326D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */; };
7085DDB426D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */; };
7085DDB526D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */; };
7087A93C28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
7087A93D28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
7087A93E28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
7087A93F28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */; };
708CADCF2872263D0066C279 /* ParseKeychainAccessGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */; };
708CADD02872263D0066C279 /* ParseKeychainAccessGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */; };
708CADD12872263D0066C279 /* ParseKeychainAccessGroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */; };
Expand Down Expand Up @@ -1273,7 +1269,6 @@
7085DD9326CBF3A70033B977 /* Documentation.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Documentation.docc; sourceTree = "<group>"; };
7085DDA226CC8A470033B977 /* ParseHealth+combine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ParseHealth+combine.swift"; sourceTree = "<group>"; };
7085DDB226D1EC7F0033B977 /* ParseAuthenticationCombineTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseAuthenticationCombineTests.swift; sourceTree = "<group>"; };
7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ParseOperation+keyPath.swift"; sourceTree = "<group>"; };
708CADCE2872263D0066C279 /* ParseKeychainAccessGroupTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseKeychainAccessGroupTests.swift; sourceTree = "<group>"; };
708D035125215F9B00646C70 /* Deletable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deletable.swift; sourceTree = "<group>"; };
709A147C283949D100BF85E5 /* ParseSchema.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseSchema.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2140,7 +2135,6 @@
F97B464024D9C78B00F4A88B /* ParseOperation.swift */,
703B091026BD992E005A112F /* ParseOperation+async.swift */,
7044C19E25C4FA870011F6E7 /* ParseOperation+combine.swift */,
7087A93B28C558CA00656E93 /* ParseOperation+keyPath.swift */,
91285B1B26990D7F0051B544 /* ParsePolygon.swift */,
705025BC284C610C008D6624 /* ParsePush.swift */,
705025C1284C7841008D6624 /* ParsePush+async.swift */,
Expand Down Expand Up @@ -2703,7 +2697,6 @@
91285B1C26990D7F0051B544 /* ParsePolygon.swift in Sources */,
91BB8FCA2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
7085DD9426CBF3A70033B977 /* Documentation.docc in Sources */,
7087A93C28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
705025EB285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
705025A928441C96008D6624 /* ParseFieldOptions.swift in Sources */,
F97B45D624D9C6F200F4A88B /* ParseEncoder.swift in Sources */,
Expand Down Expand Up @@ -3013,7 +3006,6 @@
91285B1D26990D7F0051B544 /* ParsePolygon.swift in Sources */,
91BB8FCB2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
7085DD9526CBF3A70033B977 /* Documentation.docc in Sources */,
7087A93D28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
705025EC285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
705025AA28441C96008D6624 /* ParseFieldOptions.swift in Sources */,
F97B45D724D9C6F200F4A88B /* ParseEncoder.swift in Sources */,
Expand Down Expand Up @@ -3455,7 +3447,6 @@
91679D67268E596300F71809 /* ParseVersion.swift in Sources */,
91285B1F26990D7F0051B544 /* ParsePolygon.swift in Sources */,
91BB8FCD2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
7087A93F28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
705025EE285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
705025AC28441C96008D6624 /* ParseFieldOptions.swift in Sources */,
7085DD9726CBF3A70033B977 /* Documentation.docc in Sources */,
Expand Down Expand Up @@ -3642,7 +3633,6 @@
91679D66268E596300F71809 /* ParseVersion.swift in Sources */,
91285B1E26990D7F0051B544 /* ParsePolygon.swift in Sources */,
91BB8FCC2690AC99005A6BA5 /* QueryViewModel.swift in Sources */,
7087A93E28C558CA00656E93 /* ParseOperation+keyPath.swift in Sources */,
705025ED285153BC008D6624 /* ParsePushApplePayloadable.swift in Sources */,
705025AB28441C96008D6624 /* ParseFieldOptions.swift in Sources */,
7085DD9626CBF3A70033B977 /* Documentation.docc in Sources */,
Expand Down
16 changes: 8 additions & 8 deletions Sources/ParseSwift/API/API+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,17 @@ internal extension API.Command {
let mapper = { (mapperData: Data) -> T in
var updatedObject = object
updatedObject.originalData = nil
let object = try ParseCoding
updatedObject = try ParseCoding
.jsonDecoder()
.decode(ReplaceResponse.self, from: mapperData)
.apply(to: updatedObject)
guard let originalData = data,
let original = try? ParseCoding.jsonDecoder().decode(T.self,
from: originalData),
original.hasSameObjectId(as: object) else {
return object
original.hasSameObjectId(as: updatedObject) else {
return updatedObject
}
return try object.merge(with: original)
return try updatedObject.merge(with: original)
}
return API.Command<T, T>(method: .PUT,
path: object.endpoint,
Expand All @@ -456,17 +456,17 @@ internal extension API.Command {
let mapper = { (mapperData: Data) -> T in
var updatedObject = object
updatedObject.originalData = nil
let object = try ParseCoding
updatedObject = try ParseCoding
.jsonDecoder()
.decode(UpdateResponse.self, from: mapperData)
.apply(to: updatedObject)
guard let originalData = data,
let original = try? ParseCoding.jsonDecoder().decode(T.self,
from: originalData),
original.hasSameObjectId(as: object) else {
return object
original.hasSameObjectId(as: updatedObject) else {
return updatedObject
}
return try object.merge(with: original)
return try updatedObject.merge(with: original)
}
return API.Command<T, T>(method: .PATCH,
path: object.endpoint,
Expand Down
24 changes: 15 additions & 9 deletions Sources/ParseSwift/Objects/ParseInstallation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ public extension ParseInstallation {
}

func merge(with object: Self) throws -> Self {
try mergeParse(with: object)
do {
return try mergeAutomatically(object)
} catch {
return try mergeParse(with: object)
}
}
}

Expand Down Expand Up @@ -773,15 +777,16 @@ extension ParseInstallation {
let mapper = { (data: Data) -> Self in
var updatedObject = self
updatedObject.originalData = nil
let object = try ParseCoding.jsonDecoder().decode(ReplaceResponse.self, from: data).apply(to: updatedObject)
updatedObject = try ParseCoding.jsonDecoder().decode(ReplaceResponse.self,
from: data).apply(to: updatedObject)
// MARK: The lines below should be removed when server supports PATCH.
guard let originalData = self.originalData,
let original = try? ParseCoding.jsonDecoder().decode(Self.self,
from: originalData),
original.hasSameObjectId(as: object) else {
return object
original.hasSameObjectId(as: updatedObject) else {
return updatedObject
}
return try object.merge(with: original)
return try updatedObject.merge(with: original)
}
return API.Command<Self, Self>(method: .PUT,
path: endpoint,
Expand All @@ -797,14 +802,15 @@ extension ParseInstallation {
let mapper = { (data: Data) -> Self in
var updatedObject = self
updatedObject.originalData = nil
let object = try ParseCoding.jsonDecoder().decode(UpdateResponse.self, from: data).apply(to: updatedObject)
updatedObject = try ParseCoding.jsonDecoder().decode(UpdateResponse.self,
from: data).apply(to: updatedObject)
guard let originalData = self.originalData,
let original = try? ParseCoding.jsonDecoder().decode(Self.self,
from: originalData),
original.hasSameObjectId(as: object) else {
return object
original.hasSameObjectId(as: updatedObject) else {
return updatedObject
}
return try object.merge(with: original)
return try updatedObject.merge(with: original)
}
return API.Command<Self, Self>(method: .PATCH,
path: endpoint,
Expand Down

0 comments on commit 8245f9e

Please sign in to comment.