Skip to content

Instantly share code, notes, and snippets.

View joshwcomeau's full-sized avatar

Joshua Comeau joshwcomeau

View GitHub Profile
@joshwcomeau
joshwcomeau / atu_1.jsx
Created February 9, 2016 02:29
Animating the Unanimatable
class ArticleList extends Component {
render() {
return (
<div id="article-list">
{ this.props.articles.map( article => <Article key={article.id} {...article} /> ) }
</div>
);
}
}
@joshwcomeau
joshwcomeau / atu_2.jsx
Last active February 12, 2016 13:11
Animating the Unanimatable
class ArticleList extends Component {
componentWillReceiveProps() {
this.props.children.forEach( child => {
// Find the ref for this specific child.
const ref = this.refs[child.key]
// Look up the DOM node
const domNode = ReactDOM.findDOMNode( ref );
// Calculate the bounding box
@joshwcomeau
joshwcomeau / atu_3.jsx
Last active February 12, 2016 13:14
Animating the Unanimatable
componentDidUpdate(previousProps) {
previousProps.children.forEach( child => {
let domNode = ReactDOM.findDOMNode( this.refs[child.key] );
const newBox = domNode.getBoundingClientRect();
// ...more to come
});
}
@joshwcomeau
joshwcomeau / atu_4.jsx
Last active February 12, 2016 13:22
Animating the Unanimatable
componentDidUpdate(previousProps) {
previousProps.children.forEach( child => {
let domNode = ReactDOM.findDOMNode( this.refs[child.key] );
const newBox = domNode.getBoundingClientRect();
const oldBox = this.state[key];
const deltaX = oldBox.left - newBox.left;
const deltaY = oldBox.top - newBox.top;
@joshwcomeau
joshwcomeau / atu_5.jsx
Created February 12, 2016 13:21
Animating the Unanimatable
componentDidUpdate(previousProps) {
previousProps.children.forEach( child => {
let domNode = ReactDOM.findDOMNode( this.refs[child.key] );
const newBox = domNode.getBoundingClientRect();
const oldBox = this.state[key];
const deltaX = oldBox.left - newBox.left;
const deltaY = oldBox.top - newBox.top;
@joshwcomeau
joshwcomeau / atu_6.jsx
Created February 12, 2016 13:56
Animating the Unanimatable
import React from 'react';
import FlipMove from 'react-flip-move';
const ArticleList = ({articles}) => (
<FlipMove>
{ articles.map( article => <Article key={article.id} {...article} /> ) }
</FlipMove>
);
@joshwcomeau
joshwcomeau / atu_7.jsx
Created February 12, 2016 14:01
Animating the Unanimatable
<FlipMove
duration={500}
delay={10}
easing={'cubic-bezier(0.25, 0.5, 0.75, 1)'}
staggerDurationBy={30}
staggerDelayBy={10}
onStart={startHandlerFunction}
onFinish={finishHandlerFunction}
>
{childrenWithKeys}
@joshwcomeau
joshwcomeau / package.json
Created February 26, 2016 13:10
Sample package
{
"name": "redux-thunk",
"version": "1.0.3",
"main": "lib/index.js",
"files": [
"lib",
"src"
],
"scripts": {
"build": "babel src --out-dir lib",
@joshwcomeau
joshwcomeau / immutable-props.jsx
Last active March 11, 2016 13:02
Immutable props decorator - function
const immutableProps = propsToCheck => ComposedComponent => {
return class immutablePropChecker extends Component {
shouldComponentUpdate(nextProps) {
return propsToCheck.some( p => this.props[p] !== nextProps[p] );
}
render() {
return <ComposedComponent {...this.props} />;
}
}
@joshwcomeau
joshwcomeau / immutable-props-application.jsx
Created March 11, 2016 13:03
Immutable Props decorator - application
@immutableProps(['prop1', 'prop2'])
class Thing extends Component {
// Stuff
}