Skip to content

Commit

Permalink
Move defaultProps to separate props file
Browse files Browse the repository at this point in the history
  • Loading branch information
cookpete committed Dec 24, 2015
1 parent 158fdde commit 90ef334
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
12 changes: 2 additions & 10 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import React, { Component } from 'react'
import 'array.prototype.find'

import propTypes from './propTypes'
import { propTypes, defaultProps } from './props'
import players from './players'

export default class ReactPlayer extends Component {
static propTypes = propTypes
static defaultProps = {
volume: 0.8,
width: 640,
height: 360,
onPlay: function () {}, // TODO: Empty func var in react?
onPause: function () {},
onBuffer: function () {},
onEnded: function () {}
}
static defaultProps = defaultProps
static canPlay (url) {
return players.some(player => player.canPlay(url))
}
Expand Down
6 changes: 2 additions & 4 deletions src/players/Base.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Component } from 'react'

import propTypes from '../propTypes'
import { propTypes, defaultProps } from '../props'

const UPDATE_FREQUENCY = 500

export default class Base extends Component {
static propTypes = propTypes
static defaultProps = {
onProgress: function () {}
}
static defaultProps = defaultProps
componentDidMount () {
this.update()
}
Expand Down
3 changes: 2 additions & 1 deletion src/players/FilePlayer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'

import propTypes from '../propTypes'
import { propTypes, defaultProps } from '../props'
import Base from './Base'

const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm)$/
const AUDIO_EXTENSIONS = /\.(mp3|wav)$/

export default class FilePlayer extends Base {
static propTypes = propTypes
static defaultProps = defaultProps
static canPlay (url) {
return VIDEO_EXTENSIONS.test(url) || AUDIO_EXTENSIONS.test(url)
}
Expand Down
9 changes: 2 additions & 7 deletions src/players/SoundCloud.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import React from 'react'
import loadScript from 'load-script'

import propTypes from '../propTypes'
import { propTypes, defaultProps } from '../props'
import Base from './Base'

const DEFAULT_CLIENT_ID = 'e8b6f84fbcad14c301ca1355cae1dea2'
const SDK_URL = '//connect.soundcloud.com/sdk-2.0.0.js'
const SDK_GLOBAL = 'SC'
const RESOLVE_URL = '//api.soundcloud.com/resolve.json'
const MATCH_URL = /^https?:\/\/(soundcloud.com|snd.sc)\/([a-z0-9-]+\/[a-z0-9-]+)$/

export default class SoundCloud extends Base {
static propTypes = propTypes
static defaultProps = {
soundcloudConfig: {
clientId: DEFAULT_CLIENT_ID
}
}
static defaultProps = defaultProps
static canPlay (url) {
return MATCH_URL.test(url)
}
Expand Down
6 changes: 2 additions & 4 deletions src/players/Vimeo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { stringify } from 'query-string'

import propTypes from '../propTypes'
import { propTypes, defaultProps } from '../props'
import Base from './Base'

const IFRAME_SRC = 'https://player.vimeo.com/video/'
Expand All @@ -18,9 +18,7 @@ const DEFAULT_IFRAME_PARAMS = {

export default class Vimeo extends Base {
static propTypes = propTypes
static defaultProps = {
vimeoConfig: {}
}
static defaultProps = defaultProps
static canPlay (url) {
return MATCH_URL.test(url)
}
Expand Down
6 changes: 2 additions & 4 deletions src/players/YouTube.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import loadScript from 'load-script'

import propTypes from '../propTypes'
import { propTypes, defaultProps } from '../props'
import Base from './Base'

const SDK_URL = '//www.youtube.com/iframe_api'
Expand All @@ -16,9 +16,7 @@ const DEFAULT_PLAYER_VARS = {

export default class YouTube extends Base {
static propTypes = propTypes
static defaultProps = {
youtubeConfig: {}
}
static defaultProps = defaultProps
static canPlay (url) {
return MATCH_URL.test(url)
}
Expand Down
24 changes: 23 additions & 1 deletion src/propTypes.js → src/props.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PropTypes } from 'react'

export default {
export const propTypes = {
url: PropTypes.string,
playing: PropTypes.bool,
volume: PropTypes.number,
Expand All @@ -21,3 +21,25 @@ export default {
onEnded: PropTypes.func,
onError: PropTypes.func
}

export const defaultProps = {
playing: false,
width: 640,
height: 360,
volume: 0.8,
soundcloudConfig: {
clientId: 'e8b6f84fbcad14c301ca1355cae1dea2'
},
youtubeConfig: {
playerVars: {}
},
vimeoConfig: {
iframeParams: {}
},
onPlay: function () {},
onPause: function () {},
onBuffer: function () {},
onEnded: function () {},
onError: function () {},
onProgress: function () {}
}

0 comments on commit 90ef334

Please sign in to comment.