scratch-paint/src/reducers/eraser-mode.js

32 lines
792 B
JavaScript
Raw Normal View History

2017-07-27 22:58:31 -04:00
import log from '../log/log';
const CHANGE_ERASER_SIZE = 'scratch-paint/eraser-mode/CHANGE_ERASER_SIZE';
2017-07-25 11:53:54 -04:00
const initialState = {brushSize: 20};
const reducer = function (state, action) {
if (typeof state === 'undefined') state = initialState;
switch (action.type) {
case CHANGE_ERASER_SIZE:
2017-07-27 22:58:31 -04:00
if (isNaN(action.brushSize)) {
log.warn(`Invalid brush size: ${action.brushSize}`);
return state;
}
2017-07-25 11:53:54 -04:00
return {brushSize: Math.max(1, action.brushSize)};
default:
return state;
}
};
// Action creators ==================================
const changeBrushSize = function (brushSize) {
2017-07-25 11:53:54 -04:00
return {
type: CHANGE_ERASER_SIZE,
2017-07-27 23:05:43 -04:00
brushSize: brushSize
2017-07-25 11:53:54 -04:00
};
};
export {
reducer as default,
changeBrushSize
};