yield put({
type: BEGIN_FETCHING
})
yield put({
type: END_FETCHING
})
class ProtectedRoute extends Component {
render() {
const {component, ...rest} = this.props
return <Route {...rest} render = {this.getComponent}/>
}
getComponent = (...args) => {
return this.props.user && this.props.access.indexOf(this.props.user.role) !== -1 ? <Main title={this.props.title} ><this.props.component {...args} /></Main> :
<ErrorPage/>
}
}
export default connect(state => ({
user: userSelector(state)
}), null, null, { pure: false })(ProtectedRoute)
componentDidMount (){
this.props.initialize({name : "vasya"})
}
export const getObjects = (obj, key, val) => {
let objects = []
for (let i in obj) {
if (!obj.hasOwnProperty(i)) continue
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val))
} else if (i == key && obj[key] == val) {
objects.push(obj)
}
}
return objects
}
import {appName} from '../config'
import {Record} from 'immutable'
import {createSelector} from 'reselect'
/**
* Constants
* */
export const moduleName = 'bitcoin'
const prefix = `${appName}/${moduleName}`
export const INIT = `${prefix}/INIT`
/**
* Reducer
* */
const ReducerRecord = Record({
bitcoin: null
})
export default function reducer(state = new ReducerRecord(), action) {
const {type, payload} = action
switch (type) {
case INIT:
return state.set('bitcoin', payload)
default:
return state
}
}
/**
* Selectors
* */
export const bitcoinSelector = state => state[moduleName].bitcoin
/**
* Action Creators
* */
export function bitcointInit(url) {
return (dispatch) => {
fetch(url)
.then((data) => {
dispatch({
type: INIT,
payload: data
})
});
}
}