From 58123210ab4cdd4a1f2b4720a0abbd88908baa06 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 14:44:21 +0900 Subject: [PATCH] separate settings --- src/background/index.js | 2 +- src/components/background.js | 2 +- src/content/index.js | 2 +- src/reducers/index.js | 3 ++- src/settings/actions/index.js | 4 ++++ src/{ => settings}/actions/setting.js | 2 +- src/{ => settings}/components/setting.js | 2 +- .../settings.html => settings/index.html} | 0 src/{pages/settings.js => settings/index.js} | 6 ++--- src/{ => settings}/reducers/setting.js | 2 +- .../settings.scss => settings/site.scss} | 0 test/reducers/setting.test.js | 22 ------------------- webpack.config.js | 4 ++-- 13 files changed, 17 insertions(+), 34 deletions(-) create mode 100644 src/settings/actions/index.js rename src/{ => settings}/actions/setting.js (94%) rename src/{ => settings}/components/setting.js (95%) rename src/{pages/settings.html => settings/index.html} (100%) rename src/{pages/settings.js => settings/index.js} (67%) rename src/{ => settings}/reducers/setting.js (87%) rename src/{pages/settings.scss => settings/site.scss} (100%) delete mode 100644 test/reducers/setting.test.js diff --git a/src/background/index.js b/src/background/index.js index 63d13cb..c51754b 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,4 +1,4 @@ -import * as settingsActions from 'actions/setting'; +import * as settingsActions from 'settings/actions/setting'; import messages from 'shared/messages'; import BackgroundComponent from 'components/background'; import reducers from 'reducers'; diff --git a/src/components/background.js b/src/components/background.js index afb90c2..200fedf 100644 --- a/src/components/background.js +++ b/src/components/background.js @@ -1,6 +1,6 @@ import messages from 'shared/messages'; import * as operationActions from 'actions/operation'; -import * as settingsActions from 'actions/setting'; +import * as settingsActions from 'settings/actions/setting'; import * as tabActions from 'actions/tab'; import * as commands from 'shared/commands'; diff --git a/src/content/index.js b/src/content/index.js index 25a2e74..edca510 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,6 +1,6 @@ import './console-frame.scss'; import * as consoleFrames from './console-frames'; -import * as settingActions from 'actions/setting'; +import * as settingActions from 'settings/actions/setting'; import { createStore } from 'store'; import ContentInputComponent from 'components/content-input'; import KeymapperComponent from 'components/keymapper'; diff --git a/src/reducers/index.js b/src/reducers/index.js index 3ebe491..9c86ebf 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,7 +1,8 @@ import inputReducer from 'reducers/input'; -import settingReducer from 'reducers/setting'; +import settingReducer from 'settings/reducers/setting'; import followReducer from 'reducers/follow'; +// Make setting reducer instead of re-use const defaultState = { input: inputReducer(undefined, {}), setting: settingReducer(undefined, {}), diff --git a/src/settings/actions/index.js b/src/settings/actions/index.js new file mode 100644 index 0000000..8c212c2 --- /dev/null +++ b/src/settings/actions/index.js @@ -0,0 +1,4 @@ +export default { + // Settings + SETTING_SET_SETTINGS: 'setting.set.settings', +}; diff --git a/src/actions/setting.js b/src/settings/actions/setting.js similarity index 94% rename from src/actions/setting.js rename to src/settings/actions/setting.js index c241428..697bcf0 100644 --- a/src/actions/setting.js +++ b/src/settings/actions/setting.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'settings/actions'; import messages from 'shared/messages'; import DefaultSettings from 'shared/default-settings'; diff --git a/src/components/setting.js b/src/settings/components/setting.js similarity index 95% rename from src/components/setting.js rename to src/settings/components/setting.js index c2f99b6..14482a3 100644 --- a/src/components/setting.js +++ b/src/settings/components/setting.js @@ -1,4 +1,4 @@ -import * as settingActions from 'actions/setting'; +import * as settingActions from 'settings/actions/setting'; import { validate } from 'shared/validators/setting'; export default class SettingComponent { diff --git a/src/pages/settings.html b/src/settings/index.html similarity index 100% rename from src/pages/settings.html rename to src/settings/index.html diff --git a/src/pages/settings.js b/src/settings/index.js similarity index 67% rename from src/pages/settings.js rename to src/settings/index.js index 6e25e6f..8c60f80 100644 --- a/src/pages/settings.js +++ b/src/settings/index.js @@ -1,6 +1,6 @@ -import './settings.scss'; -import SettingComponent from 'components/setting'; -import settingReducer from 'reducers/setting'; +import './site.scss'; +import SettingComponent from 'settings/components/setting'; +import settingReducer from 'settings/reducers/setting'; import { createStore } from 'store'; const store = createStore(settingReducer); diff --git a/src/reducers/setting.js b/src/settings/reducers/setting.js similarity index 87% rename from src/reducers/setting.js rename to src/settings/reducers/setting.js index 7326ed7..f7d9242 100644 --- a/src/reducers/setting.js +++ b/src/settings/reducers/setting.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'settings/actions'; const defaultState = { settings: {} diff --git a/src/pages/settings.scss b/src/settings/site.scss similarity index 100% rename from src/pages/settings.scss rename to src/settings/site.scss diff --git a/test/reducers/setting.test.js b/test/reducers/setting.test.js deleted file mode 100644 index 1af031a..0000000 --- a/test/reducers/setting.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import { expect } from "chai"; -import actions from 'actions'; -import settingReducer from 'reducers/setting'; - -describe("setting reducer", () => { - it('return the initial state', () => { - let state = settingReducer(undefined, {}); - expect(state).to.have.deep.property('settings', {}); - }); - - it('return next state for SETTING_SET_SETTINGS', () => { - let action = { - type: actions.SETTING_SET_SETTINGS, - settings: { value1: 'hello', value2: 'world' }, - }; - let state = settingReducer(undefined, action); - expect(state).to.have.deep.property('settings', { - value1: 'hello', - value2: 'world', - }); - }); -}); diff --git a/webpack.config.js b/webpack.config.js index 486814a..bc3bb1c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,7 @@ const dist = path.resolve(__dirname, 'build'); module.exports = { entry: { index: path.join(src, 'content'), - settings: path.join(src, 'pages/settings'), + settings: path.join(src, 'settings'), background: path.join(src, 'background'), console: path.join(src, 'console') }, @@ -50,7 +50,7 @@ module.exports = { inject: false }), new HtmlWebpackPlugin({ - template: path.join(src, 'pages', 'settings.html'), + template: path.join(src, 'settings', 'index.html'), filename: path.join(dist, 'settings.html'), inject: false })