【发布时间】:2016-08-12 08:44:12
【问题描述】:
是否可以在reducer 本身中调度一个动作?我有一个进度条和一个音频元素。目标是在音频元素中的时间更新时更新进度条。但是我不知道ontimeupdate事件处理程序放在哪里,或者如何在ontimeupdate的回调中调度一个动作来更新进度条。这是我的代码:
//reducer
const initialState = {
audioElement: new AudioElement('test.mp3'),
progress: 0.0
}
initialState.audioElement.audio.ontimeupdate = () => {
console.log('progress', initialState.audioElement.currentTime/initialState.audioElement.duration);
//how to dispatch 'SET_PROGRESS_VALUE' now?
};
const audio = (state=initialState, action) => {
switch(action.type){
case 'SET_PROGRESS_VALUE':
return Object.assign({}, state, {progress: action.progress});
default: return state;
}
}
export default audio;
【问题讨论】:
-
什么是
AudioElement?看起来这不应该是状态。 -
它是一个 ES6 普通类(无反应),持有一个音频对象。如果它不会处于该状态,我将如何控制播放/停止、跳过等?
-
你可能想看看 redux saga