Skip to content

Commit

Permalink
Remove legacy config props
Browse files Browse the repository at this point in the history
Breaking changes:
- Legacy config props will no longer work
  • Loading branch information
cookpete committed Apr 12, 2020
1 parent 1baa227 commit 9339efa
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 118 deletions.
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ There is a single `config` prop to override settings for each type of player:
/>
```

The old style [config props](https://github.com/CookPete/react-player/tree/v0.23.0#config-props) still work but will produce a console warning:

```jsx
<ReactPlayer
url={url}
youtubeConfig={{ playerVars: { showinfo: 1 } }}
facebookConfig={{ appId: '12345' }}
/>
```

Settings for each player live under different keys:

Key | Options
Expand Down Expand Up @@ -297,7 +287,7 @@ You can also specify a `type` for each source by using objects with `src` and `t
/>
```

[`<track>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track) elements for subtitles can be added using `fileConfig`:
[`<track>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track) elements for subtitles can be added using `config.file`:

```jsx
<ReactPlayer
Expand Down
7 changes: 0 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ export interface ReactPlayerProps {
light?: boolean | string;
wrapper?: any;
config?: Config;
soundcloudConfig?: SoundCloudConfig;
youtubeConfig?: YouTubeConfig;
facebookConfig?: FacebookConfig;
dailymotionConfig?: DailyMotionConfig;
vimeoConfig?: VimeoConfig;
fileConfig?: FileConfig;
wistiaConfig?: WistiaConfig;
onReady?(): void;
onStart?(): void;
onPlay?(): void;
Expand Down
13 changes: 8 additions & 5 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { Component, Suspense, lazy } from 'react'
import merge from 'deepmerge'

import { propTypes, defaultProps, DEPRECATED_CONFIG_PROPS } from './props'
import { getConfig, omit, isEqual } from './utils'
import { propTypes, defaultProps } from './props'
import { omit, isEqual } from './utils'
import players from './players'
import Player from './Player'

Expand All @@ -11,6 +12,8 @@ const Preview = lazy(() => import('./Preview'))
const SUPPORTED_PROPS = Object.keys(propTypes)
let customPlayers = []

const getConfig = props => merge(defaultProps.config, props.config)

export default class ReactPlayer extends Component {
static displayName = 'ReactPlayer'
static propTypes = propTypes
Expand Down Expand Up @@ -42,7 +45,7 @@ export default class ReactPlayer extends Component {
return false
}

config = getConfig(this.props, defaultProps, true)
config = getConfig(this.props)
state = {
showPreview: !!this.props.light
}
Expand All @@ -60,7 +63,7 @@ export default class ReactPlayer extends Component {

componentDidUpdate (prevProps) {
const { light } = this.props
this.config = getConfig(this.props, defaultProps)
this.config = getConfig(this.props)
if (!prevProps.light && light) {
this.setState({ showPreview: true })
}
Expand Down Expand Up @@ -141,7 +144,7 @@ export default class ReactPlayer extends Component {
render () {
const { url, style, width, height, light, playIcon, wrapper: Wrapper } = this.props
const showPreview = this.state.showPreview && url
const otherProps = omit(this.props, SUPPORTED_PROPS, DEPRECATED_CONFIG_PROPS)
const otherProps = omit(this.props, SUPPORTED_PROPS)
const activePlayer = this.getActivePlayer(url)
const player = this.renderActivePlayer(url, activePlayer)
const preview = <Preview url={url} light={light} playIcon={playIcon} onClick={this.handleClickPreview} />
Expand Down
10 changes: 0 additions & 10 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,3 @@ export const defaultProps = {
onEnablePIP: function () {},
onDisablePIP: function () {}
}

export const DEPRECATED_CONFIG_PROPS = [
'soundcloudConfig',
'youtubeConfig',
'facebookConfig',
'dailymotionConfig',
'vimeoConfig',
'fileConfig',
'wistiaConfig'
]
18 changes: 2 additions & 16 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { isValidElement } from 'react'
import loadScript from 'load-script'
import merge from 'deepmerge'

import { DEPRECATED_CONFIG_PROPS } from './props'

const MATCH_START_QUERY = /[?&#](?:start|t)=([0-9hms]+)/
const MATCH_END_QUERY = /[?&#]end=([0-9hms]+)/
const MATCH_START_STAMP = /(\d+)(h|m|s)/g
Expand Down Expand Up @@ -97,20 +95,8 @@ export function getSDK (url, sdkGlobal, sdkReady = null, isLoaded = () => true,
})
}

export function getConfig (props, defaultProps, showWarning) {
let config = merge(defaultProps.config, props.config)
for (const p of DEPRECATED_CONFIG_PROPS) {
if (props[p]) {
const key = p.replace(/Config$/, '')
config = merge(config, { [key]: props[p] })
if (showWarning) {
const link = 'https://github.com/CookPete/react-player#config-prop'
const message = `ReactPlayer: %c${p} %cis deprecated, please use the config prop instead – ${link}`
console.warn(message, 'font-weight: bold', '')
}
}
}
return config
export function getConfig (props, defaultProps) {
return merge(defaultProps.config, props.config)
}

export function omit (object, ...arrays) {
Expand Down
9 changes: 0 additions & 9 deletions test/ReactPlayer/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ test('progressFrequency warning', t => {
stub.restore()
})

test('config - deprecated config', t => {
const stub = sinon.stub(console, 'warn')
const youtubeConfig = { playerVars: { showinfo: 1 } }
const wrapper = shallow(<ReactPlayer youtubeConfig={youtubeConfig} />)
t.true(wrapper.instance().config.youtube.playerVars.showinfo === 1)
t.true(stub.calledOnce)
stub.restore()
})

test('config - updates', t => {
const config = { youtube: { playerVars: { showinfo: 1 } } }
const wrapper = shallow(<ReactPlayer config={config} />)
Expand Down
60 changes: 0 additions & 60 deletions test/utils/getConfig.js

This file was deleted.

0 comments on commit 9339efa

Please sign in to comment.