@@ -28,7 +28,7 @@ let youtubeIframeAPI;
2828/**
2929 * A factory function used to produce an instance of YT.Player and queue function calls and proxy events of the resulting object.
3030 *
31- * @param elementId Either An existing YT.Player instance,
31+ * @param maybeElementId Either An existing YT.Player instance,
3232 * the DOM element or the id of the HTML element where the API will insert an <iframe>.
3333 * @param options See `options` (Ignored when using an existing YT.Player instance).
3434 * @param strictState A flag designating whether or not to wait for
@@ -53,10 +53,15 @@ export default (maybeElementId: YouTubePlayerType | HTMLElement | string, option
5353 options . events = YouTubePlayer . proxyEvents ( emitter ) ;
5454
5555 const playerAPIReady = new Promise ( ( resolve : ( result : YouTubePlayerType ) = > void ) => {
56- if ( typeof maybeElementId === 'string' || maybeElementId instanceof HTMLElement ) {
56+ if ( typeof maybeElementId === 'object' && maybeElementId . playVideo instanceof Function ) {
57+ const player : YouTubePlayerType = maybeElementId ;
58+
59+ resolve ( player ) ;
60+ } else {
61+ // asume maybeElementId can be rendered inside
5762 // eslint-disable-next-line promise/catch-or-return
5863 youtubeIframeAPI
59- . then ( ( YT ) => {
64+ . then ( ( YT ) => { // eslint-disable-line promise/prefer-await-to-then
6065 const player : YouTubePlayerType = new YT . Player ( maybeElementId , options ) ;
6166
6267 emitter . on ( 'ready' , ( ) => {
@@ -65,12 +70,6 @@ export default (maybeElementId: YouTubePlayerType | HTMLElement | string, option
6570
6671 return null ;
6772 } ) ;
68- } else if ( typeof maybeElementId === 'object' && maybeElementId . playVideo instanceof Function ) {
69- const player : YouTubePlayerType = maybeElementId ;
70-
71- resolve ( player ) ;
72- } else {
73- throw new TypeError ( 'Unexpected state.' ) ;
7473 }
7574 } ) ;
7675
0 commit comments