MCPcopy Index your code
hub / github.com/danvk/webdiff / computePerceptualDiffBox

Function computePerceptualDiffBox

ts/ImageDiff.tsx:47–64  ·  view source on GitHub ↗
(fp: ImageFilePair)

Source from the content-addressed store, hash-verified

45
46 const [, forceUpdate] = React.useState(0);
47 const computePerceptualDiffBox = (fp: ImageFilePair) => {
48 if (!isSameSizeImagePair(fp)) return;
49 // TODO(danvk): restructure this, it's a mess
50 (async () => {
51 const response = await fetch(`/pdiffbbox/${fp.idx}`);
52 const bbox = (await response.json()) as DiffBox;
53 const {diffData} = fp;
54 // XXX are there other fields?
55 fp.diffData = {
56 ...diffData,
57 diffBounds: bbox,
58 };
59 console.log('forcing update');
60 forceUpdate(n => n + 1); // tell react about this change
61 })().catch((error: unknown) => {
62 console.error(error);
63 });
64 };
65
66 if (pdiffMode === 'bbox' && !pair.diffData) {
67 // XXX this might shoot off unnecessary XHRs--use a Promise!

Callers 1

ImageDiffFunction · 0.85

Calls 2

isSameSizeImagePairFunction · 0.90
fetchFunction · 0.85

Tested by

no test coverage detected