Skip to content

Commit

Permalink
Add callback argument to applyPatches patched option
Browse files Browse the repository at this point in the history
  • Loading branch information
piranna committed Aug 18, 2016
1 parent 5d6617e commit c45c703
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ or
This method will iterate over the contents of the patch and apply to data provided through callbacks. The general flow for each patch index is:

- `options.loadFile(index, callback)` is called. The caller should then load the contents of the file and then pass that to the `callback(err, data)` callback. Passing an `err` will terminate further patch execution.
- `options.patched(index, content)` is called once the patch has been applied. `content` will be the return value from `applyPatch`.
- `options.patched(index, content, callback)` is called once the patch has been applied. `content` will be the return value from `applyPatch`. When it's ready, the caller should call `callback(err)` callback. Passing an `err` will terminate further patch execution.
Once all patches have been applied or an error occurs, the `options.complete(err)` callback is made.
Expand Down
8 changes: 6 additions & 2 deletions src/patch/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ export function applyPatches(uniDiff, options) {
}

let updatedContent = applyPatch(data, index, options);
options.patched(index, updatedContent);
options.patched(index, updatedContent, function(err) {
if (err) {
return options.complete(err);
}

setTimeout(processIndex, 0);
processIndex();
});
});
}
processIndex();
Expand Down
16 changes: 12 additions & 4 deletions test/patch/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,12 @@ describe('patch/apply', function() {
loadFile(index, callback) {
callback(undefined, contents[index.index]);
},
patched(index, content) {
patched(index, content, callback) {
expect(content)
.to.equal(expected[index.index])
.to.not.be.undefined;

callback();
},
complete: done
});
Expand All @@ -552,10 +554,12 @@ describe('patch/apply', function() {
loadFile(index, callback) {
callback(undefined, contents[index.index]);
},
patched(index, content) {
patched(index, content, callback) {
expect(content)
.to.equal(expected[index.index])
.to.not.be.undefined;

callback();
},
complete: done
});
Expand Down Expand Up @@ -594,10 +598,12 @@ describe('patch/apply', function() {
loadFile(index, callback) {
callback(undefined, contents[index.oldFileName]);
},
patched(index, content) {
patched(index, content, callback) {
expect(content)
.to.equal(expected[index.newFileName])
.to.not.be.undefined;

callback();
},
complete: done
});
Expand Down Expand Up @@ -649,10 +655,12 @@ foo3
loadFile(index, callback) {
callback(undefined, contents[index.oldFileName]);
},
patched(index, content) {
patched(index, content, callback) {
expect(content)
.to.equal(expected[index.newFileName])
.to.not.be.undefined;

callback();
},
complete: done
});
Expand Down

0 comments on commit c45c703

Please sign in to comment.