Skip to content
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 player refs not setting correctly. #868

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class ReactPlayer extends Component {
showPreview: !!this.props.light
}

refs = {
setRef = {
wrapper: wrapper => { this.wrapper = wrapper },
player: player => { this.player = player }
}
Expand Down Expand Up @@ -142,7 +142,7 @@ export default class ReactPlayer extends Component {
<Player
{...this.props}
key={player.key}
ref={this.refs.player}
ref={this.setRef.player}
config={config}
activePlayer={player.lazyPlayer || player}
onReady={this.handleReady}
Expand All @@ -155,7 +155,7 @@ export default class ReactPlayer extends Component {
const { showPreview } = this.state
const attributes = this.getAttributes(url)
return (
<Wrapper ref={this.refs.wrapper} style={{ ...style, width, height }} {...attributes}>
<Wrapper ref={this.setRef.wrapper} style={{ ...style, width, height }} {...attributes}>
<Suspense fallback={null}>
{showPreview
? this.renderPreview(url)
Expand Down
12 changes: 6 additions & 6 deletions test/ReactPlayer/instanceMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const COMMON_METHODS = ['getDuration', 'getCurrentTime', 'getSecondsLoaded', 'ge
for (const method of COMMON_METHODS) {
test(`${method}()`, t => {
const instance = shallow(<ReactPlayer />).instance()
instance.refs.player({ [method]: () => 123 })
instance.setRef.player({ [method]: () => 123 })
t.true(instance[method]() === 123)
})

Expand All @@ -25,14 +25,14 @@ for (const method of COMMON_METHODS) {
test('getInternalPlayer() - default', t => {
const instance = shallow(<ReactPlayer />).instance()
const getInternalPlayer = sinon.fake.returns('abc')
instance.refs.player({ getInternalPlayer })
instance.setRef.player({ getInternalPlayer })
t.true(instance.getInternalPlayer() === 'abc')
t.true(getInternalPlayer.calledOnceWith('player'))
})

test('seekTo()', t => {
const instance = shallow(<ReactPlayer />).instance()
instance.refs.player({ seekTo: sinon.fake() })
instance.setRef.player({ seekTo: sinon.fake() })
instance.seekTo(5)
t.true(instance.player.seekTo.calledOnce)
t.true(instance.player.seekTo.calledWith(5))
Expand All @@ -50,10 +50,10 @@ test('onReady()', t => {
t.true(onReady.calledWith(instance))
})

test('refs', t => {
test('setRef', t => {
const instance = shallow(<ReactPlayer />).instance()
instance.refs.player('abc')
instance.refs.wrapper('def')
instance.setRef.player('abc')
instance.setRef.wrapper('def')
t.true(instance.player === 'abc')
t.true(instance.wrapper === 'def')
})