Skip to content

Commit

Permalink
Prevent unnecessary creation of MutationObservers
Browse files Browse the repository at this point in the history
Moved inspectMediaElements to the constructor where it dynamically updates this.elements
  • Loading branch information
Quantizr authored Mar 9, 2023
1 parent 51e2e9c commit f2e29c4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/contents/lib/SpeedController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default class SpeedController {

elements: MediaElement[] = []

constructor() {
inspectMediaElements((element: MediaElement) => {
this.elements.push(element)
})
}

/**
* Fixes issues changing the playback rate by temporarily blocking `ratechange` event listeners.
*/
Expand Down Expand Up @@ -101,7 +107,7 @@ export default class SpeedController {
}

setPlaybackRate(rate: number) {
inspectMediaElements((element: MediaElement) => {
this.elements.forEach((element) => {
this.setPlaybackRateForElement(rate, element)
})
}
Expand Down

0 comments on commit f2e29c4

Please sign in to comment.