diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-02-24 20:54:35 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2019-02-24 21:58:12 +0900 |
commit | a26d8a8a1bed48a77e062914c120a23ace7bb8cf (patch) | |
tree | 29ce84b9b03e87e818197b63d77e20e5a897cf0b /src/background/domains/Setting.js | |
parent | 21788740c1d4ee28ce05d6bd09d37901d1d88b68 (diff) |
Capitalize background scripts
Diffstat (limited to 'src/background/domains/Setting.js')
-rw-r--r-- | src/background/domains/Setting.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/background/domains/Setting.js b/src/background/domains/Setting.js new file mode 100644 index 0000000..106ec0f --- /dev/null +++ b/src/background/domains/Setting.js @@ -0,0 +1,51 @@ +import DefaultSettings from '../../shared/settings/default'; +import * as settingsValues from '../../shared/settings/values'; + +export default class Setting { + constructor({ source, json, form }) { + this.obj = { + source, json, form + }; + } + + get source() { + return this.obj.source; + } + + get json() { + return this.obj.json; + } + + get form() { + return this.obj.form; + } + + value() { + let value = JSON.parse(DefaultSettings.json); + if (this.obj.source === 'json') { + value = settingsValues.valueFromJson(this.obj.json); + } else if (this.obj.source === 'form') { + value = settingsValues.valueFromForm(this.obj.form); + } + if (!value.properties) { + value.properties = {}; + } + return { ...settingsValues.valueFromJson(DefaultSettings.json), ...value }; + } + + serialize() { + return this.obj; + } + + static deserialize(obj) { + return new Setting({ source: obj.source, json: obj.json, form: obj.form }); + } + + static defaultSettings() { + return new Setting({ + source: DefaultSettings.source, + json: DefaultSettings.json, + form: {}, + }); + } +} |