Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Created December 17, 2019 17:03
Show Gist options
  • Select an option

  • Save chrisdone/f70b9ab954bd2ffbdbcd37c614c13d71 to your computer and use it in GitHub Desktop.

Select an option

Save chrisdone/f70b9ab954bd2ffbdbcd37c614c13d71 to your computer and use it in GitHub Desktop.
Differ
<script src="templates/diffDOM.js"></script>
<script>
var before = document.createElement('div');
before.innerHTML = "<p>Hello, World!: 1</p><input type='text'>";
before.childNodes[1].value = "Hello, World!"
console.log('Output: %o', before.childNodes[1].value);
var after = document.createElement('div');
after.innerHTML = "<p>Hello, World: 2</p><input type='text'><p>Whassup?</p>";
var dd = new diffDOM.DiffDOM({valueDiffing: false});
var diff = dd.diff(before, after);
console.log('Diff: %o', diff);
dd.apply(before, diff);
console.log('Patched: %o', before.innerHTML);
console.log('Form input value: %o', before.childNodes[1].value);
console.log('Output: %o', before.childNodes[1].value);
</script>
test.html:6 Output: "Hello, World!"
test.html:14 Diff: (2) [a, a]
test.html:17 Patched: "<p>Hello, World: 2</p><input type="text"><p>Whassup?</p>"
test.html:18 Form input value: "Hello, World!"
test.html:20 Output: "Hello, World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment