aboutsummaryrefslogtreecommitdiff
path: root/src/content/reducers
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/reducers')
-rw-r--r--src/content/reducers/addon.js15
-rw-r--r--src/content/reducers/addon.ts22
-rw-r--r--src/content/reducers/find.js17
-rw-r--r--src/content/reducers/find.ts25
-rw-r--r--src/content/reducers/follow-controller.ts (renamed from src/content/reducers/follow-controller.js)16
-rw-r--r--src/content/reducers/index.js11
-rw-r--r--src/content/reducers/index.ts21
-rw-r--r--src/content/reducers/input.js18
-rw-r--r--src/content/reducers/input.ts26
-rw-r--r--src/content/reducers/mark.ts (renamed from src/content/reducers/mark.js)16
-rw-r--r--src/content/reducers/setting.js16
-rw-r--r--src/content/reducers/setting.ts40
12 files changed, 160 insertions, 83 deletions
diff --git a/src/content/reducers/addon.js b/src/content/reducers/addon.js
deleted file mode 100644
index 0def55a..0000000
--- a/src/content/reducers/addon.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import actions from 'content/actions';
-
-const defaultState = {
- enabled: true,
-};
-
-export default function reducer(state = defaultState, action = {}) {
- switch (action.type) {
- case actions.ADDON_SET_ENABLED:
- return { ...state,
- enabled: action.enabled, };
- default:
- return state;
- }
-}
diff --git a/src/content/reducers/addon.ts b/src/content/reducers/addon.ts
new file mode 100644
index 0000000..2131228
--- /dev/null
+++ b/src/content/reducers/addon.ts
@@ -0,0 +1,22 @@
+import * as actions from '../actions';
+
+export interface State {
+ enabled: boolean;
+}
+
+const defaultState: State = {
+ enabled: true,
+};
+
+export default function reducer(
+ state: State = defaultState,
+ action: actions.AddonAction,
+): State {
+ switch (action.type) {
+ case actions.ADDON_SET_ENABLED:
+ return { ...state,
+ enabled: action.enabled, };
+ default:
+ return state;
+ }
+}
diff --git a/src/content/reducers/find.js b/src/content/reducers/find.js
deleted file mode 100644
index 4560e2c..0000000
--- a/src/content/reducers/find.js
+++ /dev/null
@@ -1,17 +0,0 @@
-import actions from 'content/actions';
-
-const defaultState = {
- keyword: null,
- found: false,
-};
-
-export default function reducer(state = defaultState, action = {}) {
- switch (action.type) {
- case actions.FIND_SET_KEYWORD:
- return { ...state,
- keyword: action.keyword,
- found: action.found, };
- default:
- return state;
- }
-}
diff --git a/src/content/reducers/find.ts b/src/content/reducers/find.ts
new file mode 100644
index 0000000..8c3e637
--- /dev/null
+++ b/src/content/reducers/find.ts
@@ -0,0 +1,25 @@
+import * as actions from '../actions';
+
+export interface State {
+ keyword: string | null;
+ found: boolean;
+}
+
+const defaultState: State = {
+ keyword: null,
+ found: false,
+};
+
+export default function reducer(
+ state: State = defaultState,
+ action: actions.FindAction,
+): State {
+ switch (action.type) {
+ case actions.FIND_SET_KEYWORD:
+ return { ...state,
+ keyword: action.keyword,
+ found: action.found, };
+ default:
+ return state;
+ }
+}
diff --git a/src/content/reducers/follow-controller.js b/src/content/reducers/follow-controller.ts
index 5869c47..6965704 100644
--- a/src/content/reducers/follow-controller.js
+++ b/src/content/reducers/follow-controller.ts
@@ -1,13 +1,23 @@
-import actions from 'content/actions';
+import * as actions from '../actions';
-const defaultState = {
+export interface State {
+ enabled: boolean;
+ newTab: boolean;
+ background: boolean;
+ keys: string,
+}
+
+const defaultState: State = {
enabled: false,
newTab: false,
background: false,
keys: '',
};
-export default function reducer(state = defaultState, action = {}) {
+export default function reducer(
+ state: State = defaultState,
+ action: actions.FollowAction,
+): State {
switch (action.type) {
case actions.FOLLOW_CONTROLLER_ENABLE:
return { ...state,
diff --git a/src/content/reducers/index.js b/src/content/reducers/index.js
deleted file mode 100644
index bf612a3..0000000
--- a/src/content/reducers/index.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { combineReducers } from 'redux';
-import addon from './addon';
-import find from './find';
-import setting from './setting';
-import input from './input';
-import followController from './follow-controller';
-import mark from './mark';
-
-export default combineReducers({
- addon, find, setting, input, followController, mark,
-});
diff --git a/src/content/reducers/index.ts b/src/content/reducers/index.ts
new file mode 100644
index 0000000..fb5eb84
--- /dev/null
+++ b/src/content/reducers/index.ts
@@ -0,0 +1,21 @@
+import { combineReducers } from 'redux';
+import addon, { State as AddonState } from './addon';
+import find, { State as FindState } from './find';
+import setting, { State as SettingState } from './setting';
+import input, { State as InputState } from './input';
+import followController, { State as FollowControllerState }
+ from './follow-controller';
+import mark, { State as MarkState } from './mark';
+
+export interface State {
+ addon: AddonState;
+ find: FindState;
+ setting: SettingState;
+ input: InputState;
+ followController: FollowControllerState;
+ mark: MarkState;
+}
+
+export default combineReducers({
+ addon, find, setting, input, followController, mark,
+});
diff --git a/src/content/reducers/input.js b/src/content/reducers/input.js
deleted file mode 100644
index 23e7dd2..0000000
--- a/src/content/reducers/input.js
+++ /dev/null
@@ -1,18 +0,0 @@
-import actions from 'content/actions';
-
-const defaultState = {
- keys: []
-};
-
-export default function reducer(state = defaultState, action = {}) {
- switch (action.type) {
- case actions.INPUT_KEY_PRESS:
- return { ...state,
- keys: state.keys.concat([action.key]), };
- case actions.INPUT_CLEAR_KEYS:
- return { ...state,
- keys: [], };
- default:
- return state;
- }
-}
diff --git a/src/content/reducers/input.ts b/src/content/reducers/input.ts
new file mode 100644
index 0000000..35b9075
--- /dev/null
+++ b/src/content/reducers/input.ts
@@ -0,0 +1,26 @@
+import * as actions from '../actions';
+import * as keyUtils from '../../shared/utils/keys';
+
+export interface State {
+ keys: keyUtils.Key[],
+}
+
+const defaultState: State = {
+ keys: []
+};
+
+export default function reducer(
+ state: State = defaultState,
+ action: actions.InputAction,
+): State {
+ switch (action.type) {
+ case actions.INPUT_KEY_PRESS:
+ return { ...state,
+ keys: state.keys.concat([action.key]), };
+ case actions.INPUT_CLEAR_KEYS:
+ return { ...state,
+ keys: [], };
+ default:
+ return state;
+ }
+}
diff --git a/src/content/reducers/mark.js b/src/content/reducers/mark.ts
index 2c96cc5..7409938 100644
--- a/src/content/reducers/mark.js
+++ b/src/content/reducers/mark.ts
@@ -1,12 +1,22 @@
-import actions from 'content/actions';
+import Mark from '../Mark';
+import * as actions from '../actions';
-const defaultState = {
+export interface State {
+ setMode: boolean;
+ jumpMode: boolean;
+ marks: { [key: string]: Mark };
+}
+
+const defaultState: State = {
setMode: false,
jumpMode: false,
marks: {},
};
-export default function reducer(state = defaultState, action = {}) {
+export default function reducer(
+ state: State = defaultState,
+ action: actions.MarkAction,
+): State {
switch (action.type) {
case actions.MARK_START_SET:
return { ...state, setMode: true };
diff --git a/src/content/reducers/setting.js b/src/content/reducers/setting.js
deleted file mode 100644
index a49db6d..0000000
--- a/src/content/reducers/setting.js
+++ /dev/null
@@ -1,16 +0,0 @@
-import actions from 'content/actions';
-
-const defaultState = {
- // keymaps is and arrays of key-binding pairs, which is entries of Map
- keymaps: [],
-};
-
-export default function reducer(state = defaultState, action = {}) {
- switch (action.type) {
- case actions.SETTING_SET:
- return { ...action.value };
- default:
- return state;
- }
-}
-
diff --git a/src/content/reducers/setting.ts b/src/content/reducers/setting.ts
new file mode 100644
index 0000000..9ca1380
--- /dev/null
+++ b/src/content/reducers/setting.ts
@@ -0,0 +1,40 @@
+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;
+ }
+}
+