fix hot-reload settings

jh-changes
Shin'ya Ueoka 7 years ago
parent 91ea58008c
commit c202ab0529
  1. 7
      src/content/actions/setting.js
  2. 2
      src/content/components/common/keymapper.js
  3. 3
      src/content/reducers/setting.js
  4. 4
      test/content/actions/setting.test.js

@ -2,21 +2,20 @@ import actions from 'content/actions';
import * as keyUtils from 'shared/utils/keys'; import * as keyUtils from 'shared/utils/keys';
const set = (value) => { const set = (value) => {
let maps = new Map(); let entries = [];
if (value.keymaps) { if (value.keymaps) {
let entries = Object.entries(value.keymaps).map((entry) => { entries = Object.entries(value.keymaps).map((entry) => {
return [ return [
keyUtils.fromMapKeys(entry[0]), keyUtils.fromMapKeys(entry[0]),
entry[1], entry[1],
]; ];
}); });
maps = new Map(entries);
} }
return { return {
type: actions.SETTING_SET, type: actions.SETTING_SET,
value: Object.assign({}, value, { value: Object.assign({}, value, {
keymaps: maps, keymaps: entries,
}) })
}; };
}; };

@ -25,7 +25,7 @@ export default class KeymapperComponent {
let state = this.store.getState(); let state = this.store.getState();
let input = state.input; let input = state.input;
let keymaps = state.setting.keymaps; let keymaps = new Map(state.setting.keymaps);
let matched = Array.from(keymaps.keys()).filter((mapping) => { let matched = Array.from(keymaps.keys()).filter((mapping) => {
return mapStartsWith(mapping, input.keys); return mapStartsWith(mapping, input.keys);

@ -1,7 +1,8 @@
import actions from 'content/actions'; import actions from 'content/actions';
const defaultState = { const defaultState = {
keymaps: new Map(), // keymaps is and arrays of key-binding pairs, which is entries of Map
keymaps: [],
}; };
export default function reducer(state = defaultState, action = {}) { export default function reducer(state = defaultState, action = {}) {

@ -20,8 +20,8 @@ describe("setting actions", () => {
} }
}); });
let keymaps = action.value.keymaps; let keymaps = action.value.keymaps;
let map = new Map(keymaps);
expect(action.value.keymaps).to.have.deep.all.keys( expect(map).to.have.deep.all.keys(
[ [
[{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }, [{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false },
{ key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }], { key: 'd', shiftKey: false, ctrlKey: false, altKey: false, metaKey: false }],