Skip to content

Instantly share code, notes, and snippets.

View jlongster's full-sized avatar
💭
Workin on my app

James Long jlongster

💭
Workin on my app
View GitHub Profile

Writing Generic Components

The React community has gone through several patterns for how to compose React components, but it generally has settled on a few techniques. Which one you use depends on the type of component you are building.

Using props.children

The simplest way to make a component more generic is to allow

const React = require('react');
const ReactDOM = require('react-dom');
const dom = React.DOM;
const Circle = React.createClass({
propTypes: {
x: React.PropTypes.number,
y: React.PropTypes.number,
dt: React.PropTypes.number,
var http = require('http');
var express = require('express');
var WebSocketServer = require('ws').Server;
var Net = require('net');
var Protocol = require('_debugger').Protocol;
var config = {
port: 9222,
nodeDebugPort: 5858
}
jlong-16106:~% telnet localhost 5858
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Type: connect
V8-Version: 4.5.103.35
Protocol-Version: 1
Embedding-Host: node v4.2.1
Content-Length: 0
var Immutable = require('devtools/client/shared/vendor/seamless-immutable');
var gentest = require('devtools/client/shared/vendor/gentest');
var types = gentest.types;
function maybe(type) {
return types.oneOf([type, types.constantly(null)]);
}
var foo = function () {
@jlongster
jlongster / kh.el
Last active October 28, 2015 20:23
(defun keynote-highlight ()
(interactive)
(shell-command-on-region
(region-beginning)
(region-end)
"highlight -O rtf --font-size 36 --font Inconsolata --style solarized-dark -W -J 50 -j 3 --src-lang ruby | pbcopy"))
function taskMiddleware({ dispatch, getState }) {
return next => action => {
if(isGenerator(action)) {
// Not sure how to pass args via Task.spawn, can you do
// something like this?
return Task.spawn(action, dispatch, getState);
}
return next(action);
}
}
error: patch failed: devtools/client/memory/initializer.js:1
error: devtools/client/memory/initializer.js: patch does not apply
error: patch failed: devtools/client/memory/memory.xhtml:6
error: devtools/client/memory/memory.xhtml: patch does not apply
error: patch failed: devtools/client/memory/test/unit/test_action-take-snapshot.js:1
error: devtools/client/memory/test/unit/test_action-take-snapshot.js: patch does not apply
error: patch failed: devtools/client/memory/initializer.js:1
error: devtools/client/memory/initializer.js: patch does not apply
error: patch failed: devtools/client/memory/memory.xhtml:6
error: devtools/client/memory/memory.xhtml: patch does not apply
error: patch failed: devtools/client/memory/test/unit/test_action-take-snapshot.js:1
error: devtools/client/memory/test/unit/test_action-take-snapshot.js: patch does not apply
@jlongster
jlongster / immutable-libraries.md
Last active May 6, 2024 12:37
List of immutable libraries

A lot of people mentioned other immutable JS libraries after reading my post. I thought it would be good to make a list of available ones.

There are two types of immutable libraries: simple helpers for copying JavaScript objects, and actual persistent data structure implementations. My post generally analyzed the tradeoffs between both kinds of libraries and everything applies to the below libraries in either category.

Libraries are sorted by github popularity.

Persistent Data Structures w/structural sharing