All files / src/hoc paging.js

5.56% Statements 1/18
100% Branches 0/0
0% Functions 0/13
5.88% Lines 1/17
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      3x                                                                            
import React from 'react'
import { connect } from 'react-redux'
 
const paging = (list, routeParams, props) => (Component) => {
  const actions = list.actions(routeParams)
  const selectors = list.selectors(routeParams)
  
  const mapStateToProps = (state) => {
    return {
      instances: selectors.getInstances(state),
      pages: selectors.getPages(state),
      currentPage: selectors.getCurrentPage(state),
      total: selectors.getTotal(state),
      hasNext: selectors.hasNext(state),
      hasPrev: selectors.hasPrev(state),
      pageSize: selectors.getPageSize(state)
    }
  }
  const mapDispatchToProps =  (dispatch) => {
    return {
      gotoPage: (page) => dispatch(actions.page(page)),
      first: () => dispatch(actions.first()),
      last: () => dispatch(actions.last()),
      next: () => dispatch(actions.next()),
      prev: () => dispatch(actions.prev()),
      refresh: () => dispatch(actions.refresh()),
      setOptions: (options) => dispatch(actions.setOptions(options)),
      setParams: (params) => dispatch(actions.setParams(params))
    }
  }
  
  class ListHoc extends React.Component {
    render() {
      return <Component {...this.props} {...props} />
      // restActions={actions}
    }
  }
 
  return connect(mapStateToProps, mapDispatchToProps)(ListHoc)
}
 
export default paging