Skip to content

Commit

Permalink
Merge pull request #83 from go-spatial/deploy-fix
Browse files Browse the repository at this point in the history
fixing deployment
  • Loading branch information
justenPalmer authored Apr 29, 2020
2 parents 95ea941 + b2e3d64 commit 53a9ab2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/model/preference/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

import {fromJS} from 'immutable'

import Store from '../../Store'
import actions from '../actions'
import constants from './constants'
import utilLocalStorage from '../../utility/utilLocalStorage'

const init = async ()=>{
// load preference from localStorage
const preferenceJs = utilLocalStorage.get(constants.localStoragePath)
if (preferenceJs){
const preferenceImm = fromJS(preferenceJs)

Store.dispatch({
type:'PREFERENCE_SET',
payload:{
preference: preferenceImm,
}
})

return
}
}

const localBackup = async ()=>{
const state = Store.getState()
const js = state.preference.options.toJS()

utilLocalStorage.set(constants.localStoragePath, js)
}

const setIn = async({path, value})=>{
if (!path) throw new Error('preference.actions.setIn: no path defined')

Store.dispatch({
type:'PREFERENCE_SETIN',
payload:{
path,
value,
}
})

await localBackup()
}

actions.subscribe('preference',{
setIn,
})

export default {
init,
setIn,
}
6 changes: 6 additions & 0 deletions src/model/preference/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const localStoragePath = 'frescoPreferenceStore'

export default {
localStoragePath,
}
9 changes: 9 additions & 0 deletions src/model/preference/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import actions from './actions'
import constants from './constants'
import selectors from './selectors'

export default {
actions,
constants,
selectors,
}
28 changes: 28 additions & 0 deletions src/model/preference/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Map} from 'immutable'

const state = {
options: Map({}),
}

export const reducer = (st = state, action)=>{
switch (action.type){
case 'PREFERENCE_SETIN':{
const {path, value} = action.payload
const options = st.options.setIn(path, value)

return {
...st,
options,
}
}
case 'PREFERENCE_SET':{
const {preference} = action.payload
return {
...st,
options: preference
}
}
default:
return st
}
}
5 changes: 5 additions & 0 deletions src/model/preference/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
getIn: (state, {path})=>{
return state.preference.options.getIn(path)
},
}

0 comments on commit 53a9ab2

Please sign in to comment.