This repository has been archived on 2020-04-04. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Vim-Vixen/src/content/reducers/mark.ts
2019-05-06 22:17:18 +09:00

35 lines
825 B
TypeScript

import Mark from '../Mark';
import * as actions from '../actions';
export interface State {
setMode: boolean;
jumpMode: boolean;
marks: { [key: string]: Mark };
}
const defaultState: State = {
setMode: false,
jumpMode: false,
marks: {},
};
export default function reducer(
state: State = defaultState,
action: actions.MarkAction,
): State {
switch (action.type) {
case actions.MARK_START_SET:
return { ...state, setMode: true };
case actions.MARK_START_JUMP:
return { ...state, jumpMode: true };
case actions.MARK_CANCEL:
return { ...state, setMode: false, jumpMode: false };
case actions.MARK_SET_LOCAL: {
let marks = { ...state.marks };
marks[action.key] = { x: action.x, y: action.y };
return { ...state, setMode: false, marks };
}
default:
return state;
}
}