Removed old mutation queue code
This commit is contained in:
parent
e46c74d7b9
commit
f56df09e36
@ -1,6 +1,5 @@
|
|||||||
import { Application } from "./Application"
|
import { Application } from "./Application"
|
||||||
import { Diff } from "./Diff"
|
import { Diff } from "./Diff"
|
||||||
import { MutationQueue } from "./MutationQueue"
|
|
||||||
import { StatusMessage } from "./StatusMessage"
|
import { StatusMessage } from "./StatusMessage"
|
||||||
import { PushManager } from "./PushManager"
|
import { PushManager } from "./PushManager"
|
||||||
import { TouchController } from "./TouchController"
|
import { TouchController } from "./TouchController"
|
||||||
@ -42,12 +41,6 @@ export class AnimeNotifier {
|
|||||||
this.title = "Anime Notifier"
|
this.title = "Anime Notifier"
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
|
|
||||||
// this.elementFound = new MutationQueue(elem => elem.classList.add("element-found"))
|
|
||||||
// this.elementFoundRemove = new MutationQueue(elem => elem.classList.remove("element-found"))
|
|
||||||
// this.elementNotFound = new MutationQueue(elem => elem.classList.add("element-not-found"))
|
|
||||||
// this.elementColorPreview = new MutationQueue(elem => elem.classList.add("element-color-preview"))
|
|
||||||
// this.unmount = new MutationQueue(elem => elem.classList.remove("mounted"))
|
|
||||||
|
|
||||||
// These classes will never be removed on DOM diffs
|
// These classes will never be removed on DOM diffs
|
||||||
Diff.persistentClasses.add("mounted")
|
Diff.persistentClasses.add("mounted")
|
||||||
Diff.persistentClasses.add("element-found")
|
Diff.persistentClasses.add("element-found")
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { MutationQueue, CustomMutationQueue } from "./MutationQueue"
|
import { MutationQueue } from "./MutationQueue"
|
||||||
|
|
||||||
export class Diff {
|
export class Diff {
|
||||||
static persistentClasses = new Set<string>()
|
static persistentClasses = new Set<string>()
|
||||||
@ -7,7 +7,7 @@ export class Diff {
|
|||||||
// Reuse container for diffs to avoid memory allocation
|
// Reuse container for diffs to avoid memory allocation
|
||||||
static container: HTMLElement
|
static container: HTMLElement
|
||||||
static rootContainer: HTMLElement
|
static rootContainer: HTMLElement
|
||||||
static mutations: CustomMutationQueue = new CustomMutationQueue()
|
static mutations: MutationQueue = new MutationQueue()
|
||||||
|
|
||||||
// innerHTML will diff the element with the given HTML string and apply DOM mutations.
|
// innerHTML will diff the element with the given HTML string and apply DOM mutations.
|
||||||
static innerHTML(aRoot: HTMLElement, html: string): Promise<void> {
|
static innerHTML(aRoot: HTMLElement, html: string): Promise<void> {
|
||||||
|
@ -1,49 +1,6 @@
|
|||||||
const timeCapacity = 6.5
|
const timeCapacity = 6.5
|
||||||
|
|
||||||
export class MutationQueue {
|
export class MutationQueue {
|
||||||
elements: Array<HTMLElement>
|
|
||||||
mutation: (elem: HTMLElement) => void
|
|
||||||
|
|
||||||
constructor(mutation: (elem: HTMLElement) => void) {
|
|
||||||
this.mutation = mutation
|
|
||||||
this.elements = []
|
|
||||||
}
|
|
||||||
|
|
||||||
queue(elem: HTMLElement) {
|
|
||||||
this.elements.push(elem)
|
|
||||||
|
|
||||||
if(this.elements.length === 1) {
|
|
||||||
window.requestAnimationFrame(() => this.mutateAll())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mutateAll() {
|
|
||||||
let start = performance.now()
|
|
||||||
|
|
||||||
for(let i = 0; i < this.elements.length; i++) {
|
|
||||||
if(performance.now() - start > timeCapacity) {
|
|
||||||
let end = performance.now()
|
|
||||||
this.elements = this.elements.slice(i)
|
|
||||||
window.requestAnimationFrame(() => this.mutateAll())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.mutation(this.elements[i])
|
|
||||||
} catch(err) {
|
|
||||||
console.error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
clear() {
|
|
||||||
this.elements.length = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CustomMutationQueue {
|
|
||||||
mutations: Array<() => void>
|
mutations: Array<() => void>
|
||||||
onClearCallBack: () => void
|
onClearCallBack: () => void
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user