-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathroutesMap.js
44 lines (36 loc) · 1 KB
/
routesMap.js
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
import { redirect } from 'redux-first-router'
export default {
HOME: '/',
LIST: {
path: '/list/:category',
thunk: async (dispatch, getState) => {
const { payload: { category } } = getState().location
const packages = await fetch(`/api/category/${category}`)
if (packages.length === 0) {
const action = redirect({
type: 'LIST',
payload: { category: 'redux' }
})
return dispatch(action)
}
dispatch({ type: 'PACKAGES_FETCHED', payload: { category, packages } })
}
}
}
// this is essentially faking/mocking the fetch api
// pretend this actually requested data over the network
const fetch = async path => {
const category = path.replace('/api/category/', '')
switch (category) {
case 'redux':
return ['reselect', 'recompose', 'redux-first-router']
case 'react':
return [
'react-router',
'react-transition-group',
'react-universal-component'
]
default:
return []
}
}