Improved diffs

This commit is contained in:
Eduard Urbach 2017-07-19 04:18:56 +02:00
parent 1d3d069766
commit 574ac9e885
2 changed files with 22 additions and 1 deletions

View File

@ -30,6 +30,10 @@ export class AnimeNotifier {
this.imageNotFound = new MutationQueue(elem => elem.classList.add("image-not-found")) this.imageNotFound = new MutationQueue(elem => elem.classList.add("image-not-found"))
this.unmount = new MutationQueue(elem => elem.classList.remove("mounted")) this.unmount = new MutationQueue(elem => elem.classList.remove("mounted"))
// These classes will never be removed on DOM diffs
Diff.persistentClasses.add("mounted")
Diff.persistentClasses.add("image-found")
if("IntersectionObserver" in window) { if("IntersectionObserver" in window) {
// Enable lazy load // Enable lazy load
this.visibilityObserver = new IntersectionObserver( this.visibilityObserver = new IntersectionObserver(

View File

@ -1,4 +1,6 @@
export class Diff { export class Diff {
static persistentClasses = new Set<string>()
// Reuse container for diffs to avoid memory allocation // Reuse container for diffs to avoid memory allocation
static container: HTMLElement static container: HTMLElement
@ -82,7 +84,22 @@ export class Diff {
if(attrib.specified) { if(attrib.specified) {
// Skip mountables // Skip mountables
if(attrib.name == "class" && (elemA.classList.contains("mounted") || elemA.classList.contains("image-found"))) { if(attrib.name == "class") {
let classesA = elemA.classList
let classesB = elemB.classList
for(let className of classesA) {
if(!classesB.contains(className) && !Diff.persistentClasses.has(className)) {
classesA.remove(className)
}
}
for(let className of classesB) {
if(!classesA.contains(className)) {
classesA.add(className)
}
}
continue continue
} }