diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-22 00:01:24 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2018-07-22 00:01:24 +0900 |
commit | 89c28d67fd7b961833b557da904bd17aa28660c5 (patch) | |
tree | 2af29fb34f81e9dba508a4bccad98fad73dea143 /src/background/usecases/setting.js | |
parent | 0652131de885df3ebb7c9c0e762fd1604486a892 (diff) |
Settings as clean architecture
Diffstat (limited to 'src/background/usecases/setting.js')
-rw-r--r-- | src/background/usecases/setting.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/background/usecases/setting.js b/src/background/usecases/setting.js new file mode 100644 index 0000000..656fc3f --- /dev/null +++ b/src/background/usecases/setting.js @@ -0,0 +1,31 @@ +import Setting from '../domains/setting'; +import PersistentSettingRepository from '../repositories/persistent-setting'; +import SettingRepository from '../repositories/setting'; + +export default class SettingInteractor { + constructor() { + this.persistentSettingRepository = new PersistentSettingRepository(); + this.settingRepository = new SettingRepository(); + } + + save(settings) { + this.persistentSettingRepository.save(settings); + } + + get() { + return this.settingRepository.get(); + } + + async reload() { + let settings = await this.persistentSettingRepository.load(); + if (!settings) { + settings = Setting.defaultSettings(); + } + + let value = settings.value(); + + this.settingRepository.update(value); + + return value; + } +} |