| Total Complexity | 5 |
| Complexity/F | 1 |
| Lines of Code | 26 |
| Function Count | 5 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import { compose, branch, renderComponent, renderNothing } from 'recompose'; |
||
| 2 | import { graphql } from 'react-apollo'; |
||
| 3 | import { getGithubActivity } from 'services/graphQLQuery'; |
||
| 4 | import MainFeedComponent from 'components/MainFeedComponent'; |
||
| 5 | import SpinnerComponent from 'components/SpinnerComponent'; |
||
| 6 | import ErrorComponent from 'components/ErrorComponent'; |
||
| 7 | |||
| 8 | const isLoading = ({ activity }) => activity.loading; |
||
| 9 | const hasError = ({ activity }) => activity.error; |
||
| 10 | const hasNoData = ({ activity }) => !activity; |
||
| 11 | |||
| 12 | const nonOptimalStates = states => |
||
| 13 | compose( |
||
| 14 | ...states.map(state => branch(state.when, renderComponent(state.render))) |
||
| 15 | ); |
||
| 16 | |||
| 17 | export default compose( |
||
| 18 | graphql(getGithubActivity, { |
||
| 19 | name: 'activity' |
||
| 20 | }), |
||
| 21 | nonOptimalStates([ |
||
| 22 | { when: hasNoData, render: renderNothing() }, |
||
| 23 | { when: hasError, render: ErrorComponent }, |
||
| 24 | { when: isLoading, render: SpinnerComponent } |
||
| 25 | ]) |
||
| 26 | )(MainFeedComponent); |
||
| 27 |