Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyrmilligan committed Dec 18, 2016
2 parents ad81386 + 8b10045 commit 49bfdf7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Higher order component to enable loading states between route transitions and fe
[![Build Status](https://travis-ci.org/kellyrmilligan/react-redux-transition-manager.svg?branch=master)](https://travis-ci.org/kellyrmilligan/react-redux-transition-manager)
[![Coverage Status](https://coveralls.io/repos/github/kellyrmilligan/react-redux-transition-manager/badge.svg?branch=master)](https://coveralls.io/github/kellyrmilligan/react-redux-transition-manager?branch=master)

![transiton-manager-example](https://cloud.githubusercontent.com/assets/2642088/20978729/9466bed2-bc6f-11e6-838a-a13d0b6a6509.gif)

## Why?
There is a lot of boilerplate involved when using react router and fetching the necessary data when transitioning from route to route. This is an attempt to simplify this process with 2 primary features:

Expand Down Expand Up @@ -130,10 +132,12 @@ The [reactRouterFetch](https://github.com/kellyrmilligan/react-router-fetch) mod

`ErrorIndicator: PropTypes.element` - This will be rendered instead of `props.children` when an error occurs.

`SplashScreen: PropTypes.element` - This is the element to be shown for the initial page load. your loading indicator may be enough, so this is optional

`fetchInitial: PropTypes.bool` - This is for using this in client side apps only, this will initiate a fetch of the route right away, since the data wasn't loaded from the server.

`SplashScreen: PropTypes.element` - This is the element to be shown for the initial page load. your loading indicator may be enough, so this is optional
`showIndicatorOnInitial` - This prop will control whether or not you want to also show your loading indicator on the initial load. Depending on your ui, you may want to have a splash screen with a loading bar at the top of the page or something.

## Still to do:
- a stand alone version that does not use redux, and just uses `setState`
- add more tests for the actual component. sorry the coverage badge is so bad, i'm still learning enzyme. all the reducers are 100% covered
- if your API returns an error that you want to handle more specifically, you need to do it in your error Indicator and access your redux store. While this is serviceable, I want to provided a `pass-through`, where if an error happens on a certain route, you will be able to handle the error in the route handler instead if you want to.
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"name": "react-redux-transition-manager",
"version": "1.0.0",
"version": "1.2.1",
"description": "Higher order component to enable loading states between route transitions",
"keywords": "react, redux, react-router, transition, page, route",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/kellyrmilligan/react-redux-transition-manager"
},
"scripts": {
"build": "npm-run-all clean standard babel",
"babel": "babel src -d . -D -s",
Expand Down Expand Up @@ -35,10 +40,10 @@
"testRegex": "(/__tests__/.*|\\.(test))\\.js$",
"coverageThreshold": {
"global": {
"branches": 75,
"functions": 75,
"lines": 75,
"statements": 75
"branches": 10,
"functions": 10,
"lines": 10,
"statements": 10
}
},
"coveragePathIgnorePatterns": [
Expand Down Expand Up @@ -70,11 +75,13 @@
"babel-runtime": "^6.11.6",
"coveralls": "^2.11.15",
"cross-env": "^3.1.3",
"enzyme": "^2.6.0",
"jest": "^17.0.3",
"nodemon": "^1.9.0",
"npm-run-all": "^3.1.2",
"onchange": "^3.0.2",
"react": "^15.3.0",
"react-addons-test-utils": "^15.4.1",
"react-dom": "^15.3.0",
"react-redux": "^4.4.5",
"react-router": "^3.0.0",
Expand Down
38 changes: 38 additions & 0 deletions src/lib/__tests__/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* global describe, it, expect */
import React from 'react'
import { shallow } from 'enzyme'
import TransitionManager from '../index'
import isAppFetching from '../../redux/is-app-fetching'
import { Provider } from 'react-redux'
import { combineReducers, createStore } from 'redux'

const rootReducer = combineReducers({
isAppFetching
})

function configureStore () {
return createStore(rootReducer)
}

describe('react-route-transition-manager', () => {
it('be able to be rendered', () => {
const wrapper = shallow(
<Provider store={configureStore()}>
<TransitionManager>
<div className='app' />
</TransitionManager>
</Provider>
)
expect(wrapper.find('.app').length).toBe(1)
})
it('will render children by default', () => {
const wrapper = shallow(
<Provider store={configureStore()}>
<TransitionManager>
<div className='app' />
</TransitionManager>
</Provider>
)
expect(wrapper.find('.app').length).toBe(1)
})
})
12 changes: 7 additions & 5 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const TransitionManager = class TransitionManager extends Component {
onFetchEnd: PropTypes.func,
onError: PropTypes.func,
fetchInitial: PropTypes.bool,
showIndicatorOnInitial: PropTypes.bool,
FetchingIndicator: PropTypes.element,
ErrorIndicator: PropTypes.element,
SplashScreen: PropTypes.element
Expand All @@ -30,15 +31,16 @@ const TransitionManager = class TransitionManager extends Component {
isAppFetching: false
}

constructor (props, context) {
super(props, context)
const { fetchInitial } = props
if (fetchInitial) this.fetchRoutes()
componentWillMount () {
const { fetchInitial } = this.props
if (fetchInitial) this.fetchRoutes(this.props)
}

componentDidMount () {
const { fetchInitial, showIndicatorOnInitial } = this.props
this.node = document.createElement('div')
document.body.appendChild(this.node)
if (this.state.isAppFetching && fetchInitial && showIndicatorOnInitial) this.renderLoading(true)
}

componentWillReceiveProps (nextProps) {
Expand Down Expand Up @@ -122,7 +124,7 @@ const TransitionManager = class TransitionManager extends Component {
</div>
)
}
if (fetchInitial) {
if (fetchInitial && isAppFetching && SplashScreen) {
return (
<div>
{SplashScreen}
Expand Down

0 comments on commit 49bfdf7

Please sign in to comment.