This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default (fn, ...args) => (e) => { | |
e.preventDefault(); | |
fn(...args); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = express(); | |
app.use((req, res) => { | |
// Match routes from React Router | |
match({ history, routes, location: req.originalUrl }, (err, redirectLocation, renderProps) => { | |
Promise.all(getFetchFunctions(renderProps).map(fetchThem)).then(() => { | |
ReactDOM.renderToString( | |
<Provider> | |
<Router /> // You get the idea right? All fetches have been ran through the store, and you render out. | |
</Provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export (reducerMap, initialState) => (state = initialState, action) => { | |
const reducer = reducerMap[action.type]; | |
return reducer ? reducer(state, action) : state; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export default (render) => class extends React.Component { | |
shouldComponentUpdate(nextProps, nextState){ | |
return nextProps !== this.props; | |
} | |
render(){ | |
return render(this.props); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Provider } from 'react-redux'; | |
import App from './App'; | |
export default ( | |
<Provider> | |
{() => <App />} // Say whaaaaaat? | |
</Provider> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
// Higher order component taking care of subscribing | |
export default (Component) => class ReduxComponent extends React.Component { | |
componentDidMount(){ | |
const { store } = this.context; | |
this.unsubscribe = store.subscribe(() => this.forceUpdate()); | |
} | |
componentWillUnmount(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* So, you're writing pure components now? Awesome right? RIGHT?!?! | |
* Did you run into this yet? | |
*/ | |
import React from 'react'; | |
const Item = ({ | |
item, | |
openItem // a bound redux action creator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This fails in Chrome / Firefox, but passes in PhantomJS | |
expect($e.find('.content-wrapper').css('background-image')).toBe("url(http://xxxx/)"); | |
// This fails in PhantomJS, but passes in Chrome / Firefox | |
expect($e.find('.content-wrapper').css('background-image')).toBe('url("http://xxxx/")'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Icon from './'; | |
import createRenderer from 'utilities/createRenderer'; | |
const render = createRenderer(Icon); | |
describe('Component: Icon', () => { | |
it('has the correct attributes', () => { | |
const { output } = render({ | |
lowResSrc, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Spinner from 'react-spinner'; | |
export const loadable = (hasLoadedTest, Component) => props => hasLoadedTest(props) ? <Component { ...props } /> : <Spinner />; |