Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
codejockie committed Oct 6, 2019
1 parent 16bc166 commit e91df39
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,37 @@ import { LOCATION_CHANGE } from './actions'
* Utilises the search prop of location to construct query.
*/
const injectQuery = (location) => {
if (!location) return location
if (!location) {
return location
}

const searchQuery = location.search || window.location.search

if (typeof searchQuery !== 'string' || searchQuery.length === 0) {
return { ...location, query: {} }
return {
...location,
query: {}
}
}

// Ignore the `?` part of the search string e.g. ?username=codejockie
const search = searchQuery.substring(1)

// Split the query string on `&` e.g. ?username=codejockie&name=Kennedy
const queries = search.split('&')
// Contruct query
const query = queries.reduce((acc, currentQuery) => {
// Split on `=`, to get key and value
const [queryKey, queryValue] = currentQuery.split('=')
return { ...acc, [queryKey]: queryValue }
return {
...acc,
[queryKey]: queryValue
}
}, {})

return { ...location, query }
return {
...location,
query
}
}

const createConnectRouter = (structure) => {
Expand Down

0 comments on commit e91df39

Please sign in to comment.