Rename mode acton and reducer

jh-changes
Shin'ya Ueoka 6 years ago
parent bf283c732e
commit 2055dfb2fb
  1. 5
      src/content/actions/operation.js
  2. 10
      src/content/reducers/mark.js
  3. 16
      test/content/reducers/mark.test.js

@ -6,6 +6,7 @@ import * as focuses from 'content/focuses';
import * as urls from 'content/urls'; import * as urls from 'content/urls';
import * as consoleFrames from 'content/console-frames'; import * as consoleFrames from 'content/console-frames';
import * as addonActions from './addon'; import * as addonActions from './addon';
import * as markActions from './mark';
import * as properties from 'shared/settings/properties'; import * as properties from 'shared/settings/properties';
// eslint-disable-next-line complexity, max-lines-per-function // eslint-disable-next-line complexity, max-lines-per-function
@ -57,6 +58,10 @@ const exec = (operation, repeat, settings, addonEnabled) => {
background: operation.background, background: operation.background,
}), '*'); }), '*');
break; break;
case operations.MARK_SET_PREFIX:
return markActions.startSet();
case operations.MARK_JUMP_PREFIX:
return markActions.startJump();
case operations.NAVIGATE_HISTORY_PREV: case operations.NAVIGATE_HISTORY_PREV:
navigates.historyPrev(window); navigates.historyPrev(window);
break; break;

@ -1,19 +1,19 @@
import actions from 'content/actions'; import actions from 'content/actions';
const defaultState = { const defaultState = {
set: false, setMode: false,
jump: false, jumpMode: false,
marks: {}, marks: {},
}; };
export default function reducer(state = defaultState, action = {}) { export default function reducer(state = defaultState, action = {}) {
switch (action.type) { switch (action.type) {
case actions.MARK_START_SET: case actions.MARK_START_SET:
return { ...state, set: true }; return { ...state, setMode: true };
case actions.MARK_START_JUMP: case actions.MARK_START_JUMP:
return { ...state, jump: true }; return { ...state, jumpMode: true };
case actions.MARK_CANCEL: case actions.MARK_CANCEL:
return { ...state, set: false, jump: false }; return { ...state, setMode: false, jumpMode: false };
case actions.MARK_SET_LOCAL: { case actions.MARK_SET_LOCAL: {
let marks = { ...state.marks }; let marks = { ...state.marks };
marks[action.key] = { y: action.y }; marks[action.key] = { y: action.y };

@ -4,30 +4,30 @@ import reducer from 'content/reducers/mark';
describe("mark reducer", () => { describe("mark reducer", () => {
it('return the initial state', () => { it('return the initial state', () => {
let state = reducer(undefined, {}); let state = reducer(undefined, {});
expect(state.set).to.be.false; expect(state.setMode).to.be.false;
expect(state.jump).to.be.false; expect(state.jumpMode).to.be.false;
expect(state.marks).to.be.empty; expect(state.marks).to.be.empty;
}); });
it('starts set mode', () => { it('starts set mode', () => {
let action = { type: actions.MARK_START_SET }; let action = { type: actions.MARK_START_SET };
let state = reducer(undefined, action); let state = reducer(undefined, action);
expect(state.set).to.be.true; expect(state.setMode).to.be.true;
}); });
it('starts jump mode', () => { it('starts jump mode', () => {
let action = { type: actions.MARK_START_JUMP }; let action = { type: actions.MARK_START_JUMP };
let state = reducer(undefined, action); let state = reducer(undefined, action);
expect(state.jump).to.be.true; expect(state.jumpMode).to.be.true;
}); });
it('cancels set and jump mode', () => { it('cancels set and jump mode', () => {
let action = { type: actions.MARK_CANCEL }; let action = { type: actions.MARK_CANCEL };
let state = reducer({ set: true }, action); let state = reducer({ setMode: true }, action);
expect(state.set).to.be.false; expect(state.setMode).to.be.false;
state = reducer({ jump: true }, action); state = reducer({ jumpMode: true }, action);
expect(state.jump).to.be.false; expect(state.jumpMode).to.be.false;
}); });
it('stores local mark', () => { it('stores local mark', () => {