Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix React warnings and eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog committed Jan 18, 2017
1 parent 066e52d commit 2290496
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/Toggle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { connect } from 'react-redux'
import DisplaysChildren from './DisplaysChildren'

export default (isActive, loaded = () => true, componentLoadingMap = {}) => {
function Toggle({ component = DisplaysChildren, 'else': ElseComponent = () => null, loading = () => null, children, ...props }) {
function Toggle({ component = DisplaysChildren, else: ElseComponent = () => null,
loading = () => null, children, ...props }) {
const Component = component
const Loading = loading
const useProps = { ...props }
Expand All @@ -16,8 +17,8 @@ export default (isActive, loaded = () => true, componentLoadingMap = {}) => {
}
})

const NullComponent = ({ '@@__loaded': loaded, ...nullProps }) => ( // eslint-disable-line
!loaded ? <Loading {...nullProps} /> // eslint-disable-line
const NullComponent = ({ '@@__loaded': loadedProp, ...nullProps }) => ( // eslint-disable-line
!loadedProp ? <Loading {...nullProps} /> // eslint-disable-line
: (nullProps['@@__isActive'] ? <Component {...nullProps} /> : <ElseComponent {...nullProps} />)
)

Expand All @@ -27,11 +28,11 @@ export default (isActive, loaded = () => true, componentLoadingMap = {}) => {
}

const R = connect((state, rProps) => {
const __loaded = loaded(state, rProps) // eslint-disable-line
const loadedTest = !!loaded(state, rProps)
return {
...rProps,
'@@__isActive': __loaded && isActive(state, rProps),
'@@__loaded': __loaded
'@@__isActive': loadedTest && !!isActive(state, rProps),
'@@__loaded': loadedTest
}
})(NullComponent)

Expand All @@ -42,8 +43,9 @@ export default (isActive, loaded = () => true, componentLoadingMap = {}) => {
}

Toggle.propTypes = {
component: PropTypes.element,
loading: PropTypes.element,
component: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
loading: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
else: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
children: PropTypes.any
}
return Toggle
Expand Down
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ export function enterRoutes(routes) {
type: types.ENTER_ROUTES,
payload: routes
}
}
}

0 comments on commit 2290496

Please sign in to comment.