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/setting.ts
2019-05-07 21:08:21 +09:00

40 lines
1 KiB
TypeScript

import * as actions from '../actions';
import * as keyUtils from '../../shared/utils/keys';
import * as operations from '../../shared/operations';
import { Search, Properties, DefaultSetting } from '../../shared/Settings';
export interface State {
keymaps: { key: keyUtils.Key[], op: operations.Operation }[];
search: Search;
properties: Properties;
}
// defaultState does not refer due to the state is load from
// background on load.
const defaultState: State = {
keymaps: [],
search: DefaultSetting.search,
properties: DefaultSetting.properties,
};
export default function reducer(
state: State = defaultState,
action: actions.SettingAction,
): State {
switch (action.type) {
case actions.SETTING_SET:
return {
keymaps: Object.entries(action.settings.keymaps).map((entry) => {
return {
key: keyUtils.fromMapKeys(entry[0]),
op: entry[1],
};
}),
properties: action.settings.properties,
search: action.settings.search,
};
default:
return state;
}
}