commit c404a9da9194426791eb2bfedfe2132c74b679d2
parent 9882c10d030d27d7868296c52a257b5cd3d47903
Author: Massimo Siboldi <mdsiboldi@gmail.com>
Date: Thu, 8 Mar 2018 20:03:31 -0800
Add bpm to redux
Diffstat:
3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/src/App/index.js b/src/App/index.js
@@ -100,7 +100,6 @@ class App extends Component {
super();
let initBeats = 4;
this.state = {
- bpm: 120,
beat: 0,
playing: false,
tones: [{
@@ -238,7 +237,7 @@ class App extends Component {
this.setState({
beat: (this.state.beat + 1) % this.state.numBeats
})
- window.setTimeout(loop, (1 / this.state.bpm) * 60000);
+ window.setTimeout(loop, (1 / this.props.bpm) * 60000);
}
}
loop();
@@ -256,12 +255,6 @@ class App extends Component {
console.log('wow i got through', e.key);
}
- setBpm = (newBpm) => {
- this.setState({
- bpm: newBpm
- });
- }
-
render() {
const tones = this.state.tones.map((form, idx) => {
return (
@@ -342,8 +335,8 @@ class App extends Component {
minVal={20}
maxVal={600}
step={1}
- val={this.state.bpm}
- update={this.setBpm}
+ val={this.props.bpm}
+ update={this.props.setBpm}
/>
<Param
name="beats"
diff --git a/src/index.js b/src/index.js
@@ -7,7 +7,8 @@ import { Provider, connect } from 'preact-redux';
import { store } from './store.js';
const ConnectedApp = connect(state => state, {
- setVol: (newVol) => ({type: 'SET_VOL', volume: newVol})
+ setVol: (newVal) => ({type: 'SET_GLOBAL_VOL', value: newVal}),
+ setBpm: (newVal) => ({type: 'SET_GLOBAL_BPM', value: newVal})
})(App);
const InformedApp = <Provider store={store}><ConnectedApp /></Provider>;
diff --git a/src/store.js b/src/store.js
@@ -1,13 +1,19 @@
import { createStore } from 'redux';
const initialState = {
- volume: 0.7
+ volume: 0.7,
+ bpm: 120,
};
const reducer = (state, action) => {
let updates = {};
- if (action.type === 'SET_VOL') {
- updates.volume = action.volume;
+ switch (action.type) {
+ case 'SET_GLOBAL_VOL':
+ updates.volume = action.value;
+ break;
+ case 'SET_GLOBAL_BPM':
+ updates.bpm = action.value;
+ break;
}
return Object.assign({}, state, updates);
}