swimtracker-app/state/Reducer.js

39 lines
1.1 KiB
JavaScript

import { combineReducers } from 'redux';
import { CHANGE_THEME, CHANGE_USER_NAME, NEW_DEVICE_DATA, START_SESSION, STOP_SESSION, RESET_DEVICE_DATA } from './ActionCreators';
import { deviceStateReducer } from "./DeviceReduxCoupling";
const INITIAL_SETTINGS = {
theme: "hot",
username: "",
swimTrackerHost: "192.168.178.110",
analysis: {
peaksPerLap: 30,
windowSizeInSecs: 5,
numMeasurementsPerSec: 10,
peakDetector: 'SIMPLE', // either 'SIMPLE' or 'ZSCORE'
peakDetectorSimpleThreshold: 2500,
peakDetectorZScoreLag: 8, // peak detector z-score values
peakDetectorZScoreThreshold: 2,
peakDetectorZScoreInfluence: 0.1,
}
};
const settingsReducer = (state = INITIAL_SETTINGS, action) => {
switch (action.type) {
case CHANGE_THEME:
return { ...state, theme: action.newThemeName };
case CHANGE_USER_NAME:
return { ...state, username: action.newUsername };
default:
return state
}
};
export default combineReducers({
settings: settingsReducer,
deviceState: deviceStateReducer,
});