Skip to content

Commit

Permalink
Simplify API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagami committed Mar 9, 2017
1 parent c253728 commit b5e5e76
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
8 changes: 0 additions & 8 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
.player {
flex: 1;
min-height: 0;
position: relative;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.controls {
display: flex;
Expand Down
13 changes: 6 additions & 7 deletions example/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,12 @@ class Main extends React.PureComponent {
render() {
return (
<div className="container">
<div className="player">
<MPV
onReady={this.handleMPVReady}
onPropertyChange={this.handlePropertyChange}
/>
<div className="overlay" onClick={this.togglePause} />
</div>
<MPV
className="player"
onReady={this.handleMPVReady}
onPropertyChange={this.handlePropertyChange}
onMouseDown={this.togglePause}
/>
<div className="controls">
<button className="control" onClick={this.togglePause}>
{this.state.pause ? "▶" : "▮▮"}
Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const React = require("react");
/**
* React wrapper.
*/
class ReactMPV extends React.Component {
class ReactMPV extends React.PureComponent {
/**
* Send a command to the player.
*
Expand Down Expand Up @@ -119,23 +119,22 @@ class ReactMPV extends React.Component {
componentDidMount() {
this.node().addEventListener("message", this._handleMessage.bind(this));
}
shouldComponentUpdate(nextProps) {
return nextProps.className !== this.props.className ||
nextProps.style !== this.props.style;
}
render() {
const defaultStyle = {display: "block", width: "100%", height: "100%"};
return React.createElement("embed", {
const props = Object.assign({}, this.props, {
ref: "plugin",
type: "application/x-mpvjs",
className: this.props.className,
style: Object.assign(defaultStyle, this.props.style),
});
delete props.onReady;
delete props.onPropertyChange;
return React.createElement("embed", props);
}
}

/**
* Accepted properties.
* Accepted properties. Other properties (not documented) are applied to
* the plugin element.
*/
ReactMPV.propTypes = {
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"homepage": "https://github.com/Kagami/mpv.js#readme",
"peerDependencies": {
"react": ">=0.13.0 <16.0.0"
"react": "^15.3.0"
},
"devDependencies": {
"babel-standalone": "^6.23.1",
Expand Down

0 comments on commit b5e5e76

Please sign in to comment.