From 61806a4e7ff01e8b5fdfdcef0308a2c41fc98778 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 1 Oct 2017 10:59:47 +0900 Subject: setting as redux --- src/pages/settings.js | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'src/pages') diff --git a/src/pages/settings.js b/src/pages/settings.js index 6e00ed3..9bad967 100644 --- a/src/pages/settings.js +++ b/src/pages/settings.js @@ -1,22 +1,15 @@ import './settings.scss'; -import messages from '../content/messages'; +import SettingComponent from '../components/setting'; +import settingReducer from '../reducers/setting'; +import * as store from '../store'; -document.addEventListener('DOMContentLoaded', () => { - let form = document.getElementById('vimvixen-settings-form'); - form.addEventListener('submit', (e) => { - e.preventDefault(); - browser.storage.local.set({ - settings: { - json: e.target.elements['plain-json'].value - } - }).then(() => { - return browser.runtime.sendMessage({ - type: messages.SETTINGS_RELOAD - }); - }); - }); +const settingStore = store.createStore(settingReducer); +let settingComponent = null; + +settingStore.subscribe(() => { + settingComponent.update(); +}); - browser.storage.local.get('settings').then((value) => { - form.elements['plain-json'].value = value.settings.json; - }, console.error); +document.addEventListener('DOMContentLoaded', () => { + settingComponent = new SettingComponent(document.body, settingStore); }); -- cgit v1.2.3