Skip to content

Instantly share code, notes, and snippets.


Pete Hunt petehunt

  • Smyte
  • San Francisco, CA
View GitHub Profile
View gist:8595248

It looks like ReactDefaultPerf found some places you could add shouldComponentUpdate(). Great!

Keep in mind that just because there are lots of items in the table does not mean you need to add lots of shouldComponentUpdate() methods. Instead, simply try adding one to the highest-ranked component in the table and re-running the perf test. Often you'll see that it takes care of the other components on the list automatically for you.

For more information about shouldComponentUpdate() see

petehunt / gist:8396968
Created Jan 13, 2014
Sweet.js DSL for making persistent data structures feel imperative
View gist:8396968
macro := {
rule infix { $obj $([ $key ] ...) | $rval:expr } => {
$obj = mori.assoc_in($obj, [$key (,) ...].reverse(), $rval)
macro hash_map {
rule {{ $($key : $value) (,) ... }} => {
mori.hash_map($($key, $value) (,) ...)
View gist:8378115
function ObservableProperty(obj, key) {
this.obj = obj;
this.key = key;
ObservableProperty.prototype.get = function() {
return this.obj.get(this.key);
ObservableProperty.prototype.addObserver = function(target, method) {
View gist:7979935
var graph = new MoriModel();
graph.addNode('mykey', mori.hash_map('name', 'myvalue'));
mori.equals(graph.getNode('mykey'), mori.hash_map('name', 'myvalue'))
graph.addNode('mykey2', mori.hash_map('name', 'myvalue2'));
graph.addEdge('friends', 'mykey', 'mykey2');
petehunt / React sortable
Created Dec 9, 2013
Here's an example of React + jQuery UI sortable. The key thing to note is that we have the render() method do absolutely nothing and use componentDidUpdate() + React.renderComponent() to proxy updates through to the children. This lets us manage the DOM manually but still be able to use all the React goodies you know and love.
View React sortable
<script src=""></script>
<script src=""></script>
<link rel="stylesheet" href="" />
<script src=""></script>
<script src=""></script>
View ReactDefaultBatchingStrategy.js
* Copyright 2013 Facebook, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
View gist:7618353
First of all, I have an experimental branch with React that lets you use compile CSS animations just-in-time with our reconciliation system and use those instead of pure JS. So I recognize that they should be supported.
In my experience CSS transitions and animations work fine for things that will always animate fully and will never have the animation changed. A good example is a fade out when deleting a list item.
I've just found that in my own work most animations are tied with direct user touch manipulation (like animating out the left nav w/ parallax and opacity) which requires frame-by-frame responsiveness to touch events and inertia calculations based on the user's touch velocity. It's impossible to do this without doing frame-by-frame.
Your skepticism is definitely warranted and I complain to browser vendors whenever I see them about this. In my experience, modern (1 year old) phones can do this with minimal jank but there can still be issues. Assuming you're already avoiding reflows, here are the
View gist:6789788
// component with layout
var Link = React.createClass({
mixins: [LayoutMixin]
render: function () {
View gist:6689857
/** @jsx React.DOM */
var Hello = React.createClass({
mixins: [LinkedStateMixin],
getInitialState: function() {
return {name: 'phunt'};
render: function() {
return (
petehunt / gist:6601475
Created Sep 17, 2013
memory allocations oh no
View gist:6601475
window.addEventListener('mousemove', function() {}, false);