-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstore.js
64 lines (54 loc) · 1.59 KB
/
store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { createStore, applyMiddleware } from 'redux';
// Initial state of the application
const initialState = {
channel: '',
muted: false,
playing: false,
volume: 75,
};
// Available actions
export const actionTypes = {
STOP_PLAY: 'STOP_PLAY',
TOGGLE_MUTE: 'TOGGLE_MUTE',
TOGGLE_PLAY: 'TOGGLE_PLAY',
UPDATE_CHANNEL: 'UPDATE_CHANNEL',
UPDATE_VOLUME: 'UPDATE_VOLUME',
}
// REDUCERS
export const reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.STOP_PLAY:
return Object.assign({}, state, { playing: false });
case actionTypes.TOGGLE_MUTE:
return Object.assign({}, state, { muted: !state.muted });
case actionTypes.TOGGLE_PLAY:
return Object.assign({}, state, { playing: !state.playing });
case actionTypes.UPDATE_CHANNEL:
return Object.assign({}, state, { channel: action.channel, playing: true });
case actionTypes.UPDATE_VOLUME:
return Object.assign({}, state, { volume: action.volume });
default:
return state;
}
}
// ACTIONS
export const stopPlay = () => {
return { type: actionTypes.STOP_PLAY };
}
export const toogleMute = () => {
return { type: actionTypes.TOGGLE_MUTE };
}
export const tooglePlay = () => {
return { type: actionTypes.TOGGLE_PLAY };
}
export const updateChannel = (channel) => {
return { type: actionTypes.UPDATE_CHANNEL, channel };
}
export const updateVolume = (volume) => {
return { type: actionTypes.UPDATE_VOLUME, volume };
}
// Initialize the store
const initStore = (state = initialState) => {
return createStore(reducer, state);
}
export default initStore;