我目前在我的反應應用程序中有一個videojs組件(帶標記)。我想轉向react-redux。我試圖將這個組件的狀態存儲在reducer中。但我無法弄清楚正確的方法。她是我的代碼。將React videojs組件的狀態與Redux相結合
import assign from 'object-assign'
import cx from 'classnames'
import blacklist from 'blacklist'
import React, {Component} from 'react'
export default class PlayerLogic extends Component{
constructor() {
super();
this.state = {
player : {}
};
}
componentDidMount() {
var self = this;
var player = videojs(this.refs.video, this.props.options).ready(function() {
self.player = this;
self.player.on('play', self.handlePlay);
});
if (this.props.onPlayerInit) this.props.onPlayerInit(player);
player.markers({
markerStyle: {},
markers: [
{length: 8, startTime: 10, endTime: 15, time: 9.5, text: "Cigarette"},
{length: 2, startTime: 20, endTime: 25, time: 16, text: "Cigarette"},
],
onMarkerReached: function() {
player.pause();
},
next : function() {
// go to the next marker from current timestamp
console.log("reached");
var currentTime = player.currentTime();
for (var i = 0; i < markersList.length; i++) {
var markerTime = setting.markerTip.time(markersList[i]);
if (markerTime > currentTime) {
player.currentTime(markerTime);
break;
}
}
},
});
this.setState({ player: player });
console.log({player: player});
}
next() {
this.state.player.markers.next();
}
prev() {
this.state.player.markers.prev();
}
handlePlay(){
console.log("handle play ")
}
render() {
var props = blacklist(this.props, 'children', 'className', 'src', 'type', 'onPlay');
props.className = cx(this.props.className, 'videojs', 'video-js vjs-default-skin', 'vjs-big-play-centered');
assign(props, {
ref: 'video',
controls: true,
width: "700", height: "450"
});
return (
<div>
<video {... props}>
<source src={this.props.src} type={this.props.type} id={this.props.id}/>
</video>
<button onClick={this.next.bind(this)}>next</button>
<button onClick={this.prev.bind(this)}>prev</button>
</div>)
}
}
這是我的純粹反應成分。我該如何切換到react-redux。我知道所有的redux的基礎知識。我無法弄清楚,因爲改變狀態的代碼(player:player)僅在componentsDidMount中,我們正在通過setState方法改變狀態。