Skip to content

Commit

Permalink
Remove anonymous ref callback functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Oct 7, 2016
1 parent 609ee08 commit 26aec63
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ export default class ReactPlayer extends Component {
}
return players.map(this.renderPlayer)
}
ref = player => {
this.player = player
}
renderPlayer = Player => {
const active = Player.canPlay(this.props.url)
const { youtubeConfig, soundcloudConfig, vimeoConfig, fileConfig, ...activeProps } = this.props
const ref = player => { this.player = player }
const props = active ? { ...activeProps, ref } : {}
const props = active ? { ...activeProps, ref: this.ref } : {}
return (
<Player
key={Player.displayName}
Expand Down
5 changes: 4 additions & 1 deletion src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export default class FilePlayer extends Base {
if (!this.isReady || this.player.buffered.length === 0) return null
return this.player.buffered.end(0) / this.getDuration()
}
ref = player => {
this.player = player
}
render () {
const { url, loop, controls, fileConfig } = this.props
const Media = AUDIO_EXTENSIONS.test(url) ? 'audio' : 'video'
Expand All @@ -73,7 +76,7 @@ export default class FilePlayer extends Base {
}
return (
<Media
ref={player => { this.player = player }}
ref={this.ref}
style={style}
preload='auto'
controls={controls}
Expand Down
7 changes: 4 additions & 3 deletions src/players/SoundCloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export default class SoundCloud extends FilePlayer {
this.player.src = data.stream_url + '?client_id=' + this.clientId
}, onError)
}
ref = player => {
this.player = player
}
render () {
const { url, loop, controls } = this.props
const style = {
Expand All @@ -66,9 +69,7 @@ export default class SoundCloud extends FilePlayer {
return (
<div style={style}>
<audio
ref={player => {
this.player = player
}}
ref={this.ref}
type='audio/mpeg'
preload='auto'
style={{
Expand Down
5 changes: 4 additions & 1 deletion src/players/Vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export default class Vimeo extends Base {
const data = JSON.stringify({ method, value })
return this.iframe.contentWindow && this.iframe.contentWindow.postMessage(data, this.origin)
}
ref = iframe => {
this.iframe = iframe
}
render () {
const { fullscreen } = this.getIframeParams()
const style = {
Expand All @@ -112,7 +115,7 @@ export default class Vimeo extends Base {
}
return (
<iframe
ref={iframe => { this.iframe = iframe }}
ref={this.ref}
frameBorder='0'
style={style}
allowFullScreen={fullscreen}
Expand Down
5 changes: 4 additions & 1 deletion src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,17 @@ export default class YouTube extends Base {
if (!this.isReady || !this.player.getVideoLoadedFraction) return null
return this.player.getVideoLoadedFraction()
}
ref = container => {
this.container = container
}
render () {
const style = {
height: '100%',
display: this.props.url ? 'block' : 'none'
}
return (
<div style={style}>
<div ref={container => { this.container = container }} />
<div ref={this.ref} />
</div>
)
}
Expand Down

0 comments on commit 26aec63

Please sign in to comment.