diff
diff copied to clipboard
How do I actually apply a diff "later"?
I can't seem to figure out how to apply a diff generated by the diff
function if all I have is a target and a change object. For instance, in a client/server setup:
atServer() {
let patch = diff(prevState, newState);
client.sendPatch(patch);
}
and
client.onPatch(patch) {
let patched = applyDiff(this.state, patch); // <- what is this call?
this.processUpdatedState(patched);
}
What is the call to actually apply a diff to an object? Not "while generating the diff" using applyChange, and not "while having a direct reference to the original object" because then what's the point of diffing at all (you already have the result).
There's an applyDiff
function but its signature is applyDiff(target, source, filter)
which makes no sense: is source
supposed to be the diff object?
@Pomax I had the same problem and after a lot of work I found a way to do it with this package. The examples of this repo explain how to implement it. Greetings.
https://github.com/flitbit/diff/blob/e2b5b86add402ae4373ab025ee7e9a98e3424023/examples/capture_change_apply_elsewhere.js#L24-L30
I can't seem to figure out how to apply a diff generated by the
diff
function if all I have is a target and a change object. For instance, in a client/server setup:atServer() { let patch = diff(prevState, newState); client.sendPatch(patch); }
and
client.onPatch(patch) { let patched = applyDiff(this.state, patch); // <- what is this call? this.processUpdatedState(patched); }
What is the call to actually apply a diff to an object? Not "while generating the diff" using applyChange, and not "while having a direct reference to the original object" because then what's the point of diffing at all (you already have the result).
There's an
applyDiff
function but its signature isapplyDiff(target, source, filter)
which makes no sense: issource
supposed to be the diff object?