diff --git a/src/containers/brush-mode.jsx b/src/containers/brush-mode.jsx index 98054cc3..e81da224 100644 --- a/src/containers/brush-mode.jsx +++ b/src/containers/brush-mode.jsx @@ -41,9 +41,7 @@ class BrushMode extends React.Component { activateTool () { // TODO: This is temporary until a component that provides the brush size is hooked up this.props.canvas.addEventListener('mousewheel', this.onScroll); - - this.tool = new paper.Tool(); - this.blob.activateTool(false /* isEraser */, this.tool, this.props.brushModeState); + this.blob.activateTool(false /* isEraser */, this.props.brushModeState); // TODO Make sure a fill color is set on the brush // if(!pg.stylebar.getFillColor()) { @@ -53,8 +51,6 @@ class BrushMode extends React.Component { // TODO setup floating tool options panel in the editor // pg.toolOptionPanel.setup(options, components, function() {}); - - this.tool.activate(); } deactivateTool () { this.props.canvas.removeEventListener('mousewheel', this.onScroll); diff --git a/src/containers/eraser-mode.jsx b/src/containers/eraser-mode.jsx index ad804a32..f27f5997 100644 --- a/src/containers/eraser-mode.jsx +++ b/src/containers/eraser-mode.jsx @@ -40,9 +40,7 @@ class EraserMode extends React.Component { activateTool () { this.props.canvas.addEventListener('mousewheel', this.onScroll); - this.tool = new paper.Tool(); - this.blob.activateTool(true /* isEraser */, this.tool, this.props.eraserModeState); - this.tool.activate(); + this.blob.activateTool(true /* isEraser */, this.props.eraserModeState); } deactivateTool () { this.props.canvas.removeEventListener('mousewheel', this.onScroll); diff --git a/src/modes/blob.js b/src/modes/blob.js index c822f45f..07f7de34 100644 --- a/src/modes/blob.js +++ b/src/modes/blob.js @@ -31,8 +31,8 @@ class Blobbiness { } } - activateTool (isEraser, tool, options) { - this.tool = tool; + activateTool (isEraser, options) { + this.tool = new paper.Tool(); tool.cursorPreviewLastPoint = new paper.Point(-10000, -10000); tool.resizeCursorIfNeeded = function (point) { diff --git a/src/modes/segment-brush-helper.js b/src/modes/segment-brush-helper.js index 659ad00a..26d19a49 100644 --- a/src/modes/segment-brush-helper.js +++ b/src/modes/segment-brush-helper.js @@ -77,7 +77,6 @@ const segmentBrushHelper = function (tool) { // Smooth the path. finalPath.simplify(2); - // console.log(finalPath.segments); return finalPath; }; }; diff --git a/src/reducers/eraser-mode.js b/src/reducers/eraser-mode.js index 4f4ca50e..b543cfc6 100644 --- a/src/reducers/eraser-mode.js +++ b/src/reducers/eraser-mode.js @@ -18,11 +18,14 @@ const reducer = function (state, action) { }; // Action creators ================================== -reducer.changeBrushSize = function (brushSize) { +const changeBrushSize = function (brushSize) { return { type: CHANGE_ERASER_SIZE, brushSize: brushSize }; }; -export default reducer; +export { + reducer as default, + changeBrushSize +}; \ No newline at end of file diff --git a/src/reducers/modes.js b/src/reducers/modes.js index fa2f756a..00f12c50 100644 --- a/src/reducers/modes.js +++ b/src/reducers/modes.js @@ -19,11 +19,14 @@ const reducer = function (state, action) { }; // Action creators ================================== -reducer.changeMode = function (mode) { +const changeMode = function (mode) { return { type: CHANGE_MODE, mode: mode }; }; -export default reducer; +export { + reducer as default, + changeMode +}; diff --git a/test/unit/blob-tool-reducer.test.js b/test/unit/blob-mode-reducer.test.js similarity index 51% rename from test/unit/blob-tool-reducer.test.js rename to test/unit/blob-mode-reducer.test.js index 4ffe37fe..845b9111 100644 --- a/test/unit/blob-tool-reducer.test.js +++ b/test/unit/blob-mode-reducer.test.js @@ -1,6 +1,8 @@ /* eslint-env jest */ -import brushReducer from '../../src/reducers/brush-tool'; -import eraserReducer from '../../src/reducers/eraser-tool'; +import brushReducer from '../../src/reducers/brush-mode'; +import {changeBrushSize} from '../../src/reducers/brush-mode'; +import eraserReducer from '../../src/reducers/eraser-mode'; +import {changeBrushSize as changeEraserSize} from '../../src/reducers/eraser-mode'; test('initialState', () => { let defaultState; @@ -16,27 +18,27 @@ test('changeBrushSize', () => { let defaultState; const newBrushSize = 8078; - expect(brushReducer(defaultState /* state */, brushReducer.changeBrushSize(newBrushSize) /* action */)) + expect(brushReducer(defaultState /* state */, changeBrushSize(newBrushSize) /* action */)) .toEqual({brushSize: newBrushSize}); - expect(brushReducer(1 /* state */, brushReducer.changeBrushSize(newBrushSize) /* action */)) + expect(brushReducer(1 /* state */, changeBrushSize(newBrushSize) /* action */)) .toEqual({brushSize: newBrushSize}); - expect(eraserReducer(defaultState /* state */, eraserReducer.changeBrushSize(newBrushSize) /* action */)) + expect(eraserReducer(defaultState /* state */, changeEraserSize(newBrushSize) /* action */)) .toEqual({brushSize: newBrushSize}); - expect(eraserReducer(1 /* state */, eraserReducer.changeBrushSize(newBrushSize) /* action */)) + expect(eraserReducer(1 /* state */, changeEraserSize(newBrushSize) /* action */)) .toEqual({brushSize: newBrushSize}); }); test('invalidChangeBrushSize', () => { const origState = {brushSize: 1}; - expect(brushReducer(origState /* state */, brushReducer.changeBrushSize('invalid argument') /* action */)) + expect(brushReducer(origState /* state */, changeBrushSize('invalid argument') /* action */)) .toBe(origState); - expect(brushReducer(origState /* state */, brushReducer.changeBrushSize() /* action */)) + expect(brushReducer(origState /* state */, changeBrushSize() /* action */)) .toBe(origState); - expect(eraserReducer(origState /* state */, eraserReducer.changeBrushSize('invalid argument') /* action */)) + expect(eraserReducer(origState /* state */, changeEraserSize('invalid argument') /* action */)) .toBe(origState); - expect(eraserReducer(origState /* state */, eraserReducer.changeBrushSize() /* action */)) + expect(eraserReducer(origState /* state */, changeEraserSize() /* action */)) .toBe(origState); }); diff --git a/test/unit/modes-reducer.test.js b/test/unit/modes-reducer.test.js new file mode 100644 index 00000000..8f08ffc9 --- /dev/null +++ b/test/unit/modes-reducer.test.js @@ -0,0 +1,24 @@ +/* eslint-env jest */ +import Modes from '../../src/modes/modes'; +import reducer from '../../src/reducers/modes'; +import {changeMode} from '../../src/reducers/modes'; + +test('initialState', () => { + let defaultState; + expect(reducer(defaultState /* state */, {type: 'anything'} /* action */) in Modes).toBeTruthy(); +}); + +test('changeMode', () => { + let defaultState; + expect(reducer(defaultState /* state */, changeMode(Modes.ERASER) /* action */)).toBe(Modes.ERASER); + expect(reducer(Modes.ERASER /* state */, changeMode(Modes.ERASER) /* action */)) + .toBe(Modes.ERASER); + expect(reducer(Modes.BRUSH /* state */, changeMode(Modes.ERASER) /* action */)) + .toBe(Modes.ERASER); +}); + +test('invalidChangeMode', () => { + expect(reducer(Modes.BRUSH /* state */, changeMode('non-existant mode') /* action */)) + .toBe(Modes.BRUSH); + expect(reducer(Modes.BRUSH /* state */, changeMode() /* action */)).toBe(Modes.BRUSH); +}); diff --git a/test/unit/tools-reducer.test.js b/test/unit/tools-reducer.test.js deleted file mode 100644 index 428b3118..00000000 --- a/test/unit/tools-reducer.test.js +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-env jest */ -import ToolTypes from '../../src/tools/tool-types'; -import reducer from '../../src/reducers/tools'; - -test('initialState', () => { - let defaultState; - expect(reducer(defaultState /* state */, {type: 'anything'} /* action */) in ToolTypes).toBeTruthy(); -}); - -test('changeTool', () => { - let defaultState; - expect(reducer(defaultState /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */)).toBe(ToolTypes.ERASER); - expect(reducer(ToolTypes.ERASER /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */)) - .toBe(ToolTypes.ERASER); - expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */)) - .toBe(ToolTypes.ERASER); -}); - -test('invalidChangeTool', () => { - expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool('non-existant tool') /* action */)) - .toBe(ToolTypes.BRUSH); - expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool() /* action */)).toBe(ToolTypes.BRUSH); -});