long live ResizeObserver, let's ditch MutationObserver five-ever

This commit is contained in:
Tamius Han 2021-03-29 23:30:54 +02:00
parent 3185e500d1
commit 03f37fa1a3
2 changed files with 8 additions and 8 deletions

View File

@ -65,7 +65,7 @@ class PlayerData {
extensionMode: any;
dimensions: any;
private playerIdElement: any;
private observer: MutationObserver;
private observer: ResizeObserver;
//#endregion
constructor(videoData) {
@ -141,7 +141,7 @@ class PlayerData {
try {
if (BrowserDetect.firefox) {
this.observer = new MutationObserver(
this.observer = new ResizeObserver(
_.debounce( // don't do this too much:
this.onPlayerDimensionsChanged,
250, // do it once per this many ms
@ -154,7 +154,7 @@ class PlayerData {
} else {
// Chrome for some reason insists that this.onPlayerDimensionsChanged is not a function
// when it's not wrapped into an anonymous function
this.observer = new MutationObserver(
this.observer = new ResizeObserver(
_.debounce( // don't do this too much:
(m,o) => this.onPlayerDimensionsChanged(m,o),
250, // do it once per this many ms
@ -172,7 +172,7 @@ class PlayerData {
attributeOldValue: true,
};
this.observer.observe(this.element, observerConf);
this.observer.observe(this.element);
} catch (e) {
console.error("failed to set observer",e )
}

View File

@ -25,7 +25,7 @@ class VideoData {
//#region misc stuff
vdid: string;
video: any;
observer: MutationObserver;
observer: ResizeObserver;
extensionMode: any;
userCssClassName: string;
validationId: number;
@ -182,7 +182,7 @@ class VideoData {
// INIT OBSERVERS
try {
if (BrowserDetect.firefox) {
this.observer = new MutationObserver(
this.observer = new ResizeObserver(
_.debounce(
this.onVideoDimensionsChanged,
250,
@ -195,7 +195,7 @@ class VideoData {
} else {
// Chrome for some reason insists that this.onPlayerDimensionsChanged is not a function
// when it's not wrapped into an anonymous function
this.observer = new MutationObserver(
this.observer = new ResizeObserver(
_.debounce(
(m, o) => {
this.onVideoDimensionsChanged(m, o)
@ -211,7 +211,7 @@ class VideoData {
} catch (e) {
console.error('[VideoData] Observer setup failed:', e);
}
this.observer.observe(this.video, observerConf);
this.observer.observe(this.video);
// INIT AARD
this.arDetector = new ArDetector(this); // this starts Ar detection. needs optional parameter that prevets ardetdctor from starting