Skip to content

Instantly share code, notes, and snippets.

View joshwcomeau's full-sized avatar

Joshua Comeau joshwcomeau

View GitHub Profile
@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 / 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 / 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_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_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_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_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_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 / redux_react.js
Created December 11, 2015 12:29
Really basic Redux + React example
"use strict";
const connect = ReactRedux.connect;
const Provider = ReactRedux.Provider;
// REDUCER
const defaultState = { count: 0 };
const appReducer = (state = defaultState, action) => {
switch ( action.type ) {
case 'increment':
return _.extend({}, state, { count: state.count+1 });
@joshwcomeau
joshwcomeau / CatsShowResponse.json
Created April 27, 2015 18:27
CatsShowResponse
{
"_id": "553d327e594a1b5f1b13f198",
"url": {
"thumb": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/thumb.jpg",
"small": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/small.jpg",
"medium": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/medium.jpg",
"full": "https://s3.amazonaws.com/requestkittens/553c0437e4b0bde7020ac956-d9ed2ad384499394dde0eaa8c0ed040a/full.jpg"
},
"emotion": [
{