Fix debounce
This commit is contained in:
parent
7998e8158e
commit
e118777636
@ -482,10 +482,17 @@ class PlayerData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onPlayerDimensionsChanged(mutationList?, observer?) {
|
onPlayerDimensionsChanged: ResizeObserverCallback = _.debounce(
|
||||||
this.trackDimensionChanges();
|
(mutationList?, observer?) => {
|
||||||
this.trackEnvironmentChanges();
|
this.trackDimensionChanges();
|
||||||
}
|
this.trackEnvironmentChanges();
|
||||||
|
},
|
||||||
|
250, // do it once per this many ms
|
||||||
|
{
|
||||||
|
leading: true, // do it when we call this fallback first
|
||||||
|
trailing: true // do it after the timeout if we call this callback few more times
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
//#region player element change detection
|
//#region player element change detection
|
||||||
@ -499,29 +506,19 @@ class PlayerData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.observer = new ResizeObserver(
|
if (this.observer) {
|
||||||
_.debounce( // don't do this too much:
|
this.observer.disconnect();
|
||||||
(m,o) => {
|
}
|
||||||
this.onPlayerDimensionsChanged(m,o)
|
|
||||||
},
|
|
||||||
250, // do it once per this many ms
|
|
||||||
{
|
|
||||||
leading: true, // do it when we call this fallback first
|
|
||||||
trailing: true // do it after the timeout if we call this callback few more times
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const observerConf = {
|
this.observer = new ResizeObserver(
|
||||||
attributes: true,
|
this.onPlayerDimensionsChanged
|
||||||
// attributeFilter: ['style', 'class'],
|
);
|
||||||
attributeOldValue: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.observer.observe(this.element);
|
this.observer.observe(this.element);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("failed to set observer",e )
|
console.error("failed to set observer",e );
|
||||||
}
|
}
|
||||||
|
|
||||||
// legacy mode still exists, but acts as a fallback for observers and is triggered less
|
// legacy mode still exists, but acts as a fallback for observers and is triggered less
|
||||||
// frequently in order to avoid too many pointless checks
|
// frequently in order to avoid too many pointless checks
|
||||||
this.legacyChangeDetection();
|
this.legacyChangeDetection();
|
||||||
|
Loading…
Reference in New Issue
Block a user