ericclemmons / ericclemmons/bookshelf-manager
Add `patch` method
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 35
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
The patch method should operate like save, except it should pre-load and compute the optimal diff for saving:
var diff = function(before, after) {
var patch = after;
if (angular.isArray(after)) {
patch = [];
} else if (angular.isObject(after)) {
patch = {};
}
if (angular.isObject(before) && angular.isDefined(after)) {
// Compute difference for changed properties
angular.forEach(before, function(left, key) {
if (!angular.isDefined(after[key])) {
return false;
}
var right = after[key];
if (angular.isArray(after) || !angular.equals(left, right) || key === 'id') {
patch[key] = diff(left, right);
}
});
// Add new properties to patch
angular.forEach(after, function(right, key) {
if (!angular.isDefined(before[key])) {
patch[key] = right;
}
});
}
return patch;
};
The save method should no longer pre-fetch a deep tree, and only patch should do that for calculation only, then defer to save for the actual saving.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing save and model/API flow in the repository. Compare how save currently pre-fetches the deep tree with the requested patch behavior, then verify that patch computes the supplied diff and delegates the actual save. Done means patch performs the calculation while save no longer performs that pre-fetch.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, javascript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100