Fix debounce

This commit is contained in:
Tamius Han 2025-05-19 01:14:19 +02:00
parent 7998e8158e
commit e118777636

View File

@ -482,10 +482,17 @@ class PlayerData {
} }
} }
onPlayerDimensionsChanged(mutationList?, observer?) { onPlayerDimensionsChanged: ResizeObserverCallback = _.debounce(
(mutationList?, observer?) => {
this.trackDimensionChanges(); this.trackDimensionChanges();
this.trackEnvironmentChanges(); 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();