Slice detached element recovery encoding and audit progressive canvas
This commit is contained in:
@@ -9,11 +9,17 @@ export function diffJournal(before:Json,after:Json):JournalPatch[]|null {
|
||||
function visit(a:Json,b:Json,path:(string|number)[]){
|
||||
if(a===b||patches.length>10000)return;
|
||||
if(Array.isArray(a)&&Array.isArray(b)){
|
||||
const common=Math.min(a.length,b.length);for(let i=0;i<common;i++)visit(a[i],b[i],[...path,i]);
|
||||
const common=Math.min(a.length,b.length);for(let i=0;i<common;i++){
|
||||
const previous=a[i],next=b[i];
|
||||
// Shared immutable rows need no path allocation or recursive call.
|
||||
if(previous!==next)visit(previous,next,[...path,i]);
|
||||
}
|
||||
if(a.length!==b.length)patches.push({op:'splice',path,start:common,deleteCount:a.length-common,items:b.slice(common)});
|
||||
}else if(a&&b&&typeof a==='object'&&typeof b==='object'&&!Array.isArray(a)&&!Array.isArray(b)){
|
||||
const left=Object.keys(a),right=Object.keys(b);
|
||||
if(left.length===right.length&&left.every((key,i)=>key===right[i]))for(const key of right)visit(a[key],b[key],[...path,key]);
|
||||
if(left.length===right.length&&left.every((key,i)=>key===right[i]))for(const key of right){
|
||||
const previous=a[key],next=b[key];if(previous!==next)visit(previous,next,[...path,key]);
|
||||
}
|
||||
else patches.push({op:'set',path,value:b});
|
||||
}else patches.push({op:'set',path,value:b});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user