Improved diffs
This commit is contained in:
parent
1d3d069766
commit
574ac9e885
@ -30,6 +30,10 @@ export class AnimeNotifier {
|
||||
this.imageNotFound = new MutationQueue(elem => elem.classList.add("image-not-found"))
|
||||
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) {
|
||||
// Enable lazy load
|
||||
this.visibilityObserver = new IntersectionObserver(
|
||||
|
@ -1,4 +1,6 @@
|
||||
export class Diff {
|
||||
static persistentClasses = new Set<string>()
|
||||
|
||||
// Reuse container for diffs to avoid memory allocation
|
||||
static container: HTMLElement
|
||||
|
||||
@ -82,7 +84,22 @@ export class Diff {
|
||||
|
||||
if(attrib.specified) {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user