Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | 1x 1x 1x 9x 1x 3x 3x 1x 7x 1x 6x 6x 6x 6x 5x 5x 1x 1x 1x 9x 1x |
import { createStructuredSelector } from 'reselect'
import { findIndex, isArray, head } from 'lodash/fp'
export const getProps = createStructuredSelector({
children: props => props.children,
navigation: props => props[props.root]
})
export const findKey = key => findIndex(route => route.key === key)
export const getRouteIndex = (route, stack) => {
const find = findKey(route.key)
return find(stack)
}
const getWindowPathname = () => {
return window && window.location
? window.location.pathname
: '/'
}
const getHistoryState = history => {
const key = (Math.random() * 1e5 | 0).toString(16)
Iif (!history) {
return {
state: null,
key
}
}
Iif (history.location) {
return history.location
}
if (history.state) {
const { state, key } = history.state
return { state, key }
}
history.replaceState(Object.assign({},
history.state,
{ key }
), getWindowPathname())
return {
state: null,
key: history.state.key
}
}
/**
* Uses window.history and window.location to try to calculate
* the current route
*/
export const getCurrentRoute = (location, history) => {
return location || {
pathname: getWindowPathname(),
...getHistoryState(history || window.history || null)
}
}
export const wrapChildren = children => {
if (!isArray(children) || !children.length) {
return null
}
return children.length > 1
? <span>{children}</span>
: head(children)
}
|