-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from go-spatial/deploy-fix
fixing deployment
- Loading branch information
Showing
5 changed files
with
102 additions
and
0 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
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, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
const localStoragePath = 'frescoPreferenceStore' | ||
|
||
export default { | ||
localStoragePath, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import actions from './actions' | ||
import constants from './constants' | ||
import selectors from './selectors' | ||
|
||
export default { | ||
actions, | ||
constants, | ||
selectors, | ||
} |
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 |
---|---|---|
@@ -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 | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
getIn: (state, {path})=>{ | ||
return state.preference.options.getIn(path) | ||
}, | ||
} |