Skip to content

Commit

Permalink
Use external propTypes file
Browse files Browse the repository at this point in the history
Reduces duplication and avoids linting issues
  • Loading branch information
cookpete committed Aug 27, 2015
1 parent df8dc61 commit 225dfa0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
16 changes: 3 additions & 13 deletions src/ReactPlayer.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import React, { Component, PropTypes } from 'react'
import React, { Component } from 'react'
import 'array.prototype.find'

import propTypes from './propTypes'
import players from './players'

export default class MediaPlayer extends Component {
static propTypes = {
url: PropTypes.string,
playing: PropTypes.bool,
volume: PropTypes.number,
width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
onPlay: PropTypes.func,
onPause: PropTypes.func,
onBuffer: PropTypes.func,
onEnded: PropTypes.func,
onError: PropTypes.func
}
static propTypes = propTypes
static defaultProps = {
volume: 0.8,
width: 640,
Expand Down
17 changes: 4 additions & 13 deletions src/players/Base.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { Component, PropTypes } from 'react'
import { Component } from 'react'

import propTypes from '../propTypes'

const UPDATE_FREQUENCY = 500

export default class Base extends Component {
static propTypes = {
url: PropTypes.string,
playing: PropTypes.bool,
volume: PropTypes.number,
width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
onPlay: PropTypes.func,
onPause: PropTypes.func,
onBuffer: PropTypes.func,
onEnded: PropTypes.func,
onError: PropTypes.func
}
static propTypes = propTypes
static defaultProps = {
onProgress: function () {}
}
Expand Down
3 changes: 2 additions & 1 deletion src/players/SoundCloud.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import loadScript from 'load-script'

import propTypes from '../propTypes'
import Base from './Base'

const CLIENT_ID = 'e8b6f84fbcad14c301ca1355cae1dea2'
Expand All @@ -10,7 +11,7 @@ const RESOLVE_URL = '//api.soundcloud.com/resolve.json'
const MATCH_URL = /^https?:\/\/(soundcloud.com|snd.sc)\/(.*)$/

export default class SoundCloud extends Base {
static propTypes = Base.propTypes // HACK: Prevent lint error
static propTypes = propTypes
static canPlay (url) {
return MATCH_URL.test(url)
}
Expand Down
3 changes: 2 additions & 1 deletion src/players/Vimeo.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react'

import propTypes from '../propTypes'
import Base from './Base'

const IFRAME_SRC = 'https://player.vimeo.com/video/'
const MATCH_URL = /https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)/
const MATCH_MESSAGE_ORIGIN = /^https?:\/\/player.vimeo.com/

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

import propTypes from '../propTypes'
import Base from './Base'

const SDK_URL = '//www.youtube.com/iframe_api'
Expand All @@ -9,7 +10,7 @@ const MATCH_URL = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:em
const PLAYER_ID = 'youtube-player'

export default class YouTube extends Base {
static propTypes = Base.propTypes // HACK: Prevent lint error
static propTypes = propTypes
static canPlay (url) {
return MATCH_URL.test(url)
}
Expand Down
14 changes: 14 additions & 0 deletions src/propTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { PropTypes } from 'react'

export default {
url: PropTypes.string,
playing: PropTypes.bool,
volume: PropTypes.number,
width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]),
onPlay: PropTypes.func,
onPause: PropTypes.func,
onBuffer: PropTypes.func,
onEnded: PropTypes.func,
onError: PropTypes.func
}

0 comments on commit 225dfa0

Please sign in to comment.