Skip to content

Commit cbdde46

Browse files
committed
feat: add applyCompareDiffOnUneditedDocument util
1 parent 4106628 commit cbdde46

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Common/Helper.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import React, { SyntheticEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'
1818
import { JSONPath, JSONPathOptions } from 'jsonpath-plus'
19+
import { compare as compareJSON, applyPatch } from 'fast-json-patch'
1920
import { components } from 'react-select'
2021
import * as Sentry from '@sentry/browser'
2122
import moment from 'moment'
@@ -735,6 +736,11 @@ export const flatMapOfJSONPaths = (
735736
resultType: JSONPathOptions['resultType'] = 'path',
736737
): string[] => paths.flatMap((path) => JSONPath({ path, json, resultType }))
737738

739+
export const applyCompareDiffOnUneditedDocument = (uneditedDocument: object, editedDocument: object) => {
740+
const patch = compareJSON(uneditedDocument, editedDocument)
741+
return applyPatch(uneditedDocument, patch).newDocument
742+
}
743+
738744
/**
739745
* Returns a debounced variant of the function
740746
*/

0 commit comments

Comments
 (0)