Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Trys Mudford
committed
Jan 17, 2019
1 parent
cca978f
commit 3cb2b6a
Showing
5 changed files
with
35 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
import { DB } from '../utils/db'; | ||
const db = new DB(); | ||
|
||
export const actions = store => ({ | ||
updateSetting: (state, { key = '', value = '' }) => { | ||
const settings = { ...state.settings }; | ||
settings[key] = value; | ||
|
||
db.set('settings', key, value); | ||
boot: async (state, dbPromise) => { | ||
const db = new DB(dbPromise); | ||
|
||
return { | ||
settings, | ||
}; | ||
}, | ||
|
||
getSettings: async state => { | ||
const settingKeys = await db.keys('settings'); | ||
const savedSettings = await settingKeys.reduce(async (current, key) => { | ||
current[key] = await db.get('settings', key); | ||
return current; | ||
}, {}); | ||
|
||
return { | ||
settings: { | ||
...state.settings, | ||
...savedSettings, | ||
}, | ||
}; | ||
return { db, settings: { ...state.settings, ...savedSettings } }; | ||
}, | ||
|
||
updateSetting: (state, { key = '', value = '' }) => { | ||
if (!state.db) return; | ||
|
||
const settings = { ...state.settings }; | ||
settings[key] = value; | ||
|
||
state.db.set('settings', key, value); | ||
|
||
return { settings }; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const store = { | |
settings: { | ||
theme: '', | ||
}, | ||
db: null, | ||
}; | ||
|
||
export default createStore(store); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters