p5.js-web-editor/client/modules/IDE/reducers/preferences.js
2016-07-13 12:59:58 -04:00

57 lines
1.6 KiB
JavaScript

import * as ActionTypes from '../../../constants';
const initialState = {
isVisible: false,
fontSize: 18,
indentationAmount: 2,
isTabIndent: true
};
const preferences = (state = initialState, action) => {
switch (action.type) {
case ActionTypes.OPEN_PREFERENCES:
return Object.assign({}, state, {
isVisible: true
});
case ActionTypes.CLOSE_PREFERENCES:
return Object.assign({}, state, {
isVisible: false
});
case ActionTypes.INCREASE_FONTSIZE:
return Object.assign({}, state, {
fontSize: state.fontSize + 2
});
case ActionTypes.DECREASE_FONTSIZE:
return Object.assign({}, state, {
fontSize: state.fontSize - 2
});
case ActionTypes.UPDATE_FONTSIZE:
return Object.assign({}, state, {
fontSize: parseInt(action.value, 10)
});
case ActionTypes.INCREASE_INDENTATION:
return Object.assign({}, state, {
indentationAmount: state.indentationAmount + 2
});
case ActionTypes.DECREASE_INDENTATION:
return Object.assign({}, state, {
indentationAmount: state.indentationAmount - 2
});
case ActionTypes.UPDATE_INDENTATION:
return Object.assign({}, state, {
indentationAmount: parseInt(action.value, 10)
});
case ActionTypes.INDENT_WITH_TAB:
return Object.assign({}, state, {
isTabIndent: true
});
case ActionTypes.INDENT_WITH_SPACE:
return Object.assign({}, state, {
isTabIndent: false
});
default:
return state;
}
};
export default preferences;