-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TypeError when calling unbindVideoElement #3043
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import VideoElementResolutionMonitor, { | |
export default class DefaultVideoElementResolutionMonitor implements VideoElementResolutionMonitor { | ||
private observerQueue = new Set<VideoElementResolutionObserver>(); | ||
private resizeObserver: ResizeObserver; | ||
private element?: HTMLVideoElement; | ||
private element: HTMLVideoElement | null = null; | ||
|
||
constructor() { | ||
this.resizeObserver = new ResizeObserver(entries => { | ||
|
@@ -32,12 +32,15 @@ export default class DefaultVideoElementResolutionMonitor implements VideoElemen | |
this.observerQueue.delete(observer); | ||
} | ||
|
||
bindVideoElement(newElement: HTMLVideoElement): void { | ||
this.element = newElement; | ||
if (!this.element) { | ||
this.resizeObserver.unobserve(this.element); | ||
bindVideoElement(newElement: HTMLVideoElement | null): void { | ||
if (!newElement) { | ||
if (this.element) { | ||
this.resizeObserver.unobserve(this.element); | ||
} | ||
this.element = newElement; | ||
return; | ||
} | ||
this.element = newElement; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
this.resizeObserver.observe(this.element); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
import * as chai from 'chai'; | ||
|
||
import NoOpVideoElementFactory from '../../src/videoelementfactory/NoOpVideoElementFactory'; | ||
import DefaultVideoElementResolutionMonitor from '../../src/videotile/DefaultVideoElementResolutionMonitor'; | ||
import { VideoElementResolutionObserver } from '../../src/videotile/VideoElementResolutionMonitor'; | ||
import DOMMockBehavior from '../dommock/DOMMockBehavior'; | ||
|
@@ -70,5 +71,16 @@ describe('DefaultVideoElementResolutionMonitor', () => { | |
|
||
monitor.removeObserver(mockObserver); | ||
}); | ||
|
||
it('should bind and unbind video elements', () => { | ||
const videoElementFactory = new NoOpVideoElementFactory(); | ||
const videoElement = videoElementFactory.create(); | ||
monitor.bindVideoElement(videoElement); | ||
monitor.bindVideoElement(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need some expect statements for this test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is expected to handle these inputs. Added expect no exception to throw |
||
}); | ||
|
||
it('should skip unobserve if no element is being beserved', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
monitor.bindVideoElement(null); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicit
this.element = null
should be good.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change, makes it a bit easier to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed
ResizeObserver
can observe multiple elements. So I updated the function to unobserve the element being observed if notnull
, and then observenewElement
if not null. Also added a function to skip whennewElement
equals to the one being observed