Implemented full page diffs

This commit is contained in:
2017-07-19 05:23:06 +02:00
parent 647aed0e76
commit 197ef0197a
3 changed files with 55 additions and 11 deletions

View File

@ -3,6 +3,7 @@ export class Diff {
// Reuse container for diffs to avoid memory allocation
static container: HTMLElement
static rootContainer: HTMLElement
// innerHTML will diff the element with the given HTML string and apply DOM mutations.
static innerHTML(aRoot: HTMLElement, html: string) {
@ -14,6 +15,18 @@ export class Diff {
Diff.childNodes(aRoot, Diff.container)
}
// root will diff the document root element with the given HTML string and apply DOM mutations.
static root(aRoot: HTMLElement, html: string) {
if(!Diff.rootContainer) {
Diff.rootContainer = document.createElement("html")
}
Diff.rootContainer.innerHTML = html.replace("<!DOCTYPE html>", "")
console.log(Diff.rootContainer)
Diff.childNodes(aRoot, Diff.rootContainer)
}
// childNodes diffs the child nodes of 2 given elements and applies DOM mutations.
static childNodes(aRoot: Node, bRoot: Node) {
let aChild = [...aRoot.childNodes]