This repository has been archived by the owner on Feb 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowLoader.jsx
62 lines (53 loc) · 1.64 KB
/
ShowLoader.jsx
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
import React from 'react'
import Router from 'react-router'
import bows from 'bows'
import makeClassAdder from '../shared/services/makeClassAdder.js'
import { connect } from 'react-redux'
import actions from './actions'
import languagesUsersActions from '../languages_users/actions'
import Busy from '../shared/Busy.jsx'
import Show from './Show.jsx'
import reduxLoader from 'redux-loader'
const PT = React.PropTypes
const baseClass = 'users--ShowLoader'
const classAdder = makeClassAdder(baseClass)
const log = bows(baseClass)
const Loader = reduxLoader.create({
component: Show,
busy: Busy,
resources: {
languagesUsers: function(options) {
const id = '/languages_users'
return {
id,
find: function() {
return options.props.languages_users
},
load: function() {
const action = languagesUsersActions.fetch()
return options.dispatch(action)
},
}
},
user: function(options) {
const userId = options.props.params.id
const id = `/users/${userId}`
return {
id,
find: function() {
const user = _.find(options.props.users, {id: userId})
// log('user', user)
return user
},
load: function() {
const action = actions.fetchOne(userId)
return options.dispatch(action)
},
}
},
},
})
Loader.contextTypes = {
router: PT.object.isRequired,
}
export default connect(state => state)(Loader)