Skip to content

Commit f1de90d

Browse files
committed
fix: disable text diff for JSONPatch demo
1 parent 1f0995a commit f1de90d

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

demos/html-demo/demo.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ const getExampleJson = function () {
266266
return json;
267267
};
268268

269-
const instance = jsondiffpatch.create({
269+
const diffOptions = {
270270
objectHash: function (obj, index) {
271271
const objRecord = obj as Record<string, string>;
272272
if (typeof objRecord._id !== 'undefined') {
@@ -283,6 +283,13 @@ const instance = jsondiffpatch.create({
283283
}
284284
return '$$index:' + index;
285285
},
286+
} as jsondiffpatch.Options;
287+
const instance = jsondiffpatch.create(diffOptions);
288+
const instanceWithNoTextDiff = jsondiffpatch.create({
289+
...diffOptions,
290+
textDiff: {
291+
minLength: Number.MAX_VALUE,
292+
},
286293
});
287294

288295
const dom = {
@@ -504,7 +511,12 @@ const compare = function () {
504511
const jsondifflength = document.getElementById('jsondifflength')!;
505512
const jsonpatchlength = document.getElementById('jsonpatchlength')!;
506513
try {
507-
const delta = instance.diff(left, right);
514+
// jsonpatch format doesn't support textdiffs
515+
const noTextDiff = selectedType === 'jsonpatch';
516+
const delta = (noTextDiff ? instanceWithNoTextDiff : instance).diff(
517+
left,
518+
right,
519+
);
508520
resultsSections.setAttribute(
509521
'data-diff',
510522
typeof delta === 'undefined' ? 'no-diff' : 'has-diff',

0 commit comments

Comments
 (0)