Skip to content

Commit b2e3d64

Browse files
committed
fixing deployment
1 parent 247a4d3 commit b2e3d64

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

src/model/preference/actions.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
import {fromJS} from 'immutable'
3+
4+
import Store from '../../Store'
5+
import actions from '../actions'
6+
import constants from './constants'
7+
import utilLocalStorage from '../../utility/utilLocalStorage'
8+
9+
const init = async ()=>{
10+
// load preference from localStorage
11+
const preferenceJs = utilLocalStorage.get(constants.localStoragePath)
12+
if (preferenceJs){
13+
const preferenceImm = fromJS(preferenceJs)
14+
15+
Store.dispatch({
16+
type:'PREFERENCE_SET',
17+
payload:{
18+
preference: preferenceImm,
19+
}
20+
})
21+
22+
return
23+
}
24+
}
25+
26+
const localBackup = async ()=>{
27+
const state = Store.getState()
28+
const js = state.preference.options.toJS()
29+
30+
utilLocalStorage.set(constants.localStoragePath, js)
31+
}
32+
33+
const setIn = async({path, value})=>{
34+
if (!path) throw new Error('preference.actions.setIn: no path defined')
35+
36+
Store.dispatch({
37+
type:'PREFERENCE_SETIN',
38+
payload:{
39+
path,
40+
value,
41+
}
42+
})
43+
44+
await localBackup()
45+
}
46+
47+
actions.subscribe('preference',{
48+
setIn,
49+
})
50+
51+
export default {
52+
init,
53+
setIn,
54+
}

src/model/preference/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
const localStoragePath = 'frescoPreferenceStore'
3+
4+
export default {
5+
localStoragePath,
6+
}

src/model/preference/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import actions from './actions'
2+
import constants from './constants'
3+
import selectors from './selectors'
4+
5+
export default {
6+
actions,
7+
constants,
8+
selectors,
9+
}

src/model/preference/reducer.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {Map} from 'immutable'
2+
3+
const state = {
4+
options: Map({}),
5+
}
6+
7+
export const reducer = (st = state, action)=>{
8+
switch (action.type){
9+
case 'PREFERENCE_SETIN':{
10+
const {path, value} = action.payload
11+
const options = st.options.setIn(path, value)
12+
13+
return {
14+
...st,
15+
options,
16+
}
17+
}
18+
case 'PREFERENCE_SET':{
19+
const {preference} = action.payload
20+
return {
21+
...st,
22+
options: preference
23+
}
24+
}
25+
default:
26+
return st
27+
}
28+
}

src/model/preference/selectors.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
getIn: (state, {path})=>{
3+
return state.preference.options.getIn(path)
4+
},
5+
}

0 commit comments

Comments
 (0)