aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/background/actions/find.js10
-rw-r--r--src/background/actions/index.js3
-rw-r--r--src/background/components/background.js8
-rw-r--r--src/background/reducers/find.js16
-rw-r--r--src/background/reducers/index.js3
-rw-r--r--src/shared/messages.js2
-rw-r--r--test/background/actions/find.test.js13
-rw-r--r--test/background/reducers/find.test.js19
8 files changed, 74 insertions, 0 deletions
diff --git a/src/background/actions/find.js b/src/background/actions/find.js
new file mode 100644
index 0000000..8da5572
--- /dev/null
+++ b/src/background/actions/find.js
@@ -0,0 +1,10 @@
+import actions from './index';
+
+const setKeyword = (keyword) => {
+ return {
+ type: actions.FIND_SET_KEYWORD,
+ keyword,
+ };
+};
+
+export { setKeyword };
diff --git a/src/background/actions/index.js b/src/background/actions/index.js
index efe4074..2bdaaf2 100644
--- a/src/background/actions/index.js
+++ b/src/background/actions/index.js
@@ -2,4 +2,7 @@ export default {
// Settings
SETTING_SET_SETTINGS: 'setting.set.settings',
SETTING_SET_PROPERTY: 'setting.set.property',
+
+ // Find
+ FIND_SET_KEYWORD: 'find.set.keyword',
};
diff --git a/src/background/components/background.js b/src/background/components/background.js
index c4f436a..fdec8ec 100644
--- a/src/background/components/background.js
+++ b/src/background/components/background.js
@@ -2,6 +2,7 @@ import messages from 'shared/messages';
import * as operationActions from 'background/actions/operation';
import * as commandActions from 'background/actions/command';
import * as settingActions from 'background/actions/setting';
+import * as findActions from 'background/actions/find';
import * as tabActions from 'background/actions/tab';
import * as commands from 'shared/commands';
@@ -23,6 +24,8 @@ export default class BackgroundComponent {
onMessage(message, sender) {
let settings = this.store.getState().setting;
+ let find = this.store.getState().find;
+
switch (message.type) {
case messages.BACKGROUND_OPERATION:
return this.store.dispatch(
@@ -48,6 +51,11 @@ export default class BackgroundComponent {
case messages.SETTINGS_RELOAD:
this.store.dispatch(settingActions.load());
return this.broadcastSettingsChanged();
+ case messages.FIND_GET_KEYWORD:
+ return Promise.resolve(find.keyword);
+ case messages.FIND_SET_KEYWORD:
+ this.store.dispatch(findActions.setKeyword(message.keyword));
+ return Promise.resolve({});
}
}
diff --git a/src/background/reducers/find.js b/src/background/reducers/find.js
new file mode 100644
index 0000000..4ded801
--- /dev/null
+++ b/src/background/reducers/find.js
@@ -0,0 +1,16 @@
+import actions from 'content/actions';
+
+const defaultState = {
+ keyword: null,
+};
+
+export default function reducer(state = defaultState, action = {}) {
+ switch (action.type) {
+ case actions.FIND_SET_KEYWORD:
+ return Object.assign({}, state, {
+ keyword: action.keyword,
+ });
+ default:
+ return state;
+ }
+}
diff --git a/src/background/reducers/index.js b/src/background/reducers/index.js
index dab0c62..63ff0f8 100644
--- a/src/background/reducers/index.js
+++ b/src/background/reducers/index.js
@@ -1,12 +1,15 @@
import settingReducer from './setting';
+import findReducer from './find';
// Make setting reducer instead of re-use
const defaultState = {
setting: settingReducer(undefined, {}),
+ find: findReducer(undefined, {}),
};
export default function reducer(state = defaultState, action = {}) {
return Object.assign({}, state, {
setting: settingReducer(state.setting, action),
+ find: findReducer(state.find, action),
});
}
diff --git a/src/shared/messages.js b/src/shared/messages.js
index b7a1a7e..a404658 100644
--- a/src/shared/messages.js
+++ b/src/shared/messages.js
@@ -45,6 +45,8 @@ export default {
FIND_NEXT: 'find.next',
FIND_PREV: 'find.prev',
+ FIND_GET_KEYWORD: 'find.get.keyword',
+ FIND_SET_KEYWORD: 'find.set.keyword',
OPEN_URL: 'open.url',
diff --git a/test/background/actions/find.test.js b/test/background/actions/find.test.js
new file mode 100644
index 0000000..467604f
--- /dev/null
+++ b/test/background/actions/find.test.js
@@ -0,0 +1,13 @@
+import { expect } from "chai";
+import actions from 'background/actions';
+import * as findActions from 'background/actions/find';
+
+describe("find actions", () => {
+ describe("setKeyword", () => {
+ it('create FIND_SET_KEYWORD action', () => {
+ let action = findActions.setKeyword('banana');
+ expect(action.type).to.equal(actions.FIND_SET_KEYWORD);
+ expect(action.keyword).to.equal('banana');
+ });
+ });
+});
diff --git a/test/background/reducers/find.test.js b/test/background/reducers/find.test.js
new file mode 100644
index 0000000..707d73a
--- /dev/null
+++ b/test/background/reducers/find.test.js
@@ -0,0 +1,19 @@
+import { expect } from "chai";
+import actions from 'background/actions';
+import findReducer from 'background/reducers/find';
+
+describe("find reducer", () => {
+ it('return the initial state', () => {
+ let state = findReducer(undefined, {});
+ expect(state).to.have.deep.property('keyword', null);
+ });
+
+ it('return next state for FIND_SET_KEYWORD', () => {
+ let action = {
+ type: actions.FIND_SET_KEYWORD,
+ keyword: 'cherry',
+ };
+ let state = findReducer(undefined, action);
+ expect(state).to.have.deep.property('keyword', 'cherry')
+ });
+});