|
|
@ -46,12 +46,34 @@ const reverseMappings = mappings.map(mapping =>
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const serializeState = state => {
|
|
|
|
|
|
|
|
const stateString = encodeURIComponent(JSON.stringify(state))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return typeof window !== 'undefined'
|
|
|
|
|
|
|
|
? btoa(stateString)
|
|
|
|
|
|
|
|
: Buffer.from(stateString).toString('base64')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const deserializeState = serializedState => {
|
|
|
|
|
|
|
|
let stateString
|
|
|
|
|
|
|
|
if (typeof window !== 'undefined') {
|
|
|
|
|
|
|
|
stateString = atob(serializedState)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
stateString = Buffer.from(serializedState, 'base64').toString()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return JSON.parse(decodeURIComponent(stateString))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const keysToQuery = keys =>
|
|
|
|
const keysToQuery = keys =>
|
|
|
|
`?${Object.keys(keys)
|
|
|
|
`?${Object.keys(keys)
|
|
|
|
.map(key => `${key}=${keys[key]}`)
|
|
|
|
.map(key => `${key}=${keys[key]}`)
|
|
|
|
.join('&')}`
|
|
|
|
.join('&')}`
|
|
|
|
|
|
|
|
|
|
|
|
export const getQueryStringState = query => {
|
|
|
|
export const getQueryStringState = query => {
|
|
|
|
|
|
|
|
if (query.state) {
|
|
|
|
|
|
|
|
return deserializeState(query.state)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const state = mapper.map(mappings, query)
|
|
|
|
const state = mapper.map(mappings, query)
|
|
|
|
deserializeCode(state)
|
|
|
|
deserializeCode(state)
|
|
|
|
|
|
|
|
|
|
|
@ -61,6 +83,7 @@ export const getQueryStringState = query => {
|
|
|
|
|
|
|
|
|
|
|
|
return state
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const updateQueryString = state => {
|
|
|
|
export const updateQueryString = state => {
|
|
|
|
let mappedState = mapper.map(reverseMappings, state)
|
|
|
|
let mappedState = mapper.map(reverseMappings, state)
|
|
|
|