Skip to content

Commit

Permalink
add param mutateDocument in function applyPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
FourDirections_MaxiCho committed Sep 25, 2017
1 parent f7e15da commit 688be37
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,18 @@ export function applyOperation<T>(document: T, operation: Operation, validateOpe
* @param document The document to patch
* @param patch The patch to apply
* @param validateOperation `false` is without validation, `true` to use default jsonpatch's validation, or you can pass a `validateOperation` callback to be used for validation.
* @param mutateDocument Whether to mutate the original document or clone it before applying
* @return An array of `{newDocument, result}` after the patch
*/
export function applyPatch<T>(document: T, patch: Operation[], validateOperation?: boolean | Validator<T>): PatchResult<T> {
export function applyPatch<T>(document: T, patch: Operation[], validateOperation?: boolean | Validator<T>, mutateDocument: boolean = true): PatchResult<T> {
if(validateOperation) {
if(!Array.isArray(patch)) {
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
}
}
if (!mutateDocument) {
document = _deepClone(document);
}
const results = new Array(patch.length) as PatchResult<T>;

for (let i = 0, length = patch.length; i < length; i++) {
Expand Down

0 comments on commit 688be37

Please sign in to comment.