Closed krasnoukhov closed 8 years ago
@wvteijlingen Please let me know if this change is ok with you so I'll update the specs
Good point! Wouldn't this achieve the same thing but in a bit more readable way?
public func addResource(resource: Resource) {
resources.append(resource)
if let index = removedResources.indexOf(resource) {
removedResources.removeAtIndex(index)
} else {
addedResources.append(resource)
}
}
public func removeResource(resource: Resource) {
resources = resources.filter { $0 !== resource }
if let index = addedResources.indexOf(resource) {
addedResources.removeAtIndex(index)
} else {
removedResources.append(resource)
}
}
Good point! Commit is updated with better implementation and specs.
Nice work! I'm not sure but I think we should assert addedResources.isEmpty
in testRemoveAdded()
and removedResources.isEmpty
in testAddRemoved()
as well.
Makes sense, commit updated
Sweet!
This fixes the case when persisting changes given there were previously loaded resources. Otherwise invalid requests will be sent in attempt to create already existing relations or to remove inexistent.