Skip to content

Instantly share code, notes, and snippets.

View elierotenberg's full-sized avatar

Elie Rotenberg elierotenberg

View GitHub Profile
@elierotenberg
elierotenberg / client.jsx
Created February 8, 2015 18:27
Flux over the Wire client.jsx
const client = new FluxClient('http://localhost:8080');
const messageList = client.Store('/messageList');
const postMessage = client.Action('/postMessage');
const MessageList = React.createClass({
getInitialState() {
return { messageList: this.props.messageList.head, message: null };
},
componentDidMount() {
messageList.onUpdate(({ head }) => this.setState({ messageList: head }));
@elierotenberg
elierotenberg / isExtensionOf.js
Last active August 29, 2015 14:20
isExtensionOf
// is A an extension of B ?
// ex:
// class C extends Oject {}
// class B extends C {}
// class A extends B {}
// isExtension(A, B) === true
// isExtension(A, C) === true
// isExtension(A, Object) === true
// isExtension(B, A) === false
function isExtensionOf(A, B) {
@elierotenberg
elierotenberg / TransformProps.js
Last active August 29, 2015 14:21
TransformProps
const TransformProps = (Component, transform) => class extends React.Component {
displayName = Component.displayName;
render() {
return <Component {...transform(this.props)}>;
}
};
const transform = (f) => (t) => {
r = {};
@elierotenberg
elierotenberg / gist:6d3b7d4d3751c4ea0103
Created June 8, 2015 15:21
Composing @Nexus.component
@component(() => ({
users: ['remote://users', {}],
}))
@component(({ users }) =>
users.mapKeys((userId) =>
[`user:${userId}`, [`remote://users/${userId}`, { firstName: 'John', lastName: 'Doe' }]]
).toObject()
)
class UserList extends React.Component {
render() {
@elierotenberg
elierotenberg / Preferences.sublime-settings
Last active August 29, 2015 14:23
Preferences.sublime-settings
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Oceanic Next Color Scheme/Oceanic Next.tmTheme",
"copy_with_empty_selection": true,
"ensure_newline_at_eof_on_save": true,
"font_family": "Consolas",
"font_options": "subpixel_antialias",
"highlight_line": true,
"highlight_modified_tabs": true,
@elierotenberg
elierotenberg / super1.js
Created June 21, 2015 17:47
super return value
let x;
class A {
constructor() {
this.a = true;
// explictly returns this
return this;
}
}
const $x = Symbol();
const t = { $x: 4, y: 5, z: 6 };
const { [$x], ...collect } = t; // collect = { y: 5, z: 6 }
@elierotenberg
elierotenberg / match-with-example.js
Last active December 8, 2015 08:53
Match with in JS DSL
import match, { $, $$$ } from 'match-with';
// l is a list
const length = match(l).with(
// $() is a single-item named placeholder
// $$$() is a rest-collecting named placeholder
// .when(predicate) adds a guard predicate
clause([$('head'), $$$('tail')]).when(({ tail }) => tail.length > 0)).then(({ head, tail }) => 1 + tail.length),
@elierotenberg
elierotenberg / ComplexClass-0.js
Created December 14, 2015 16:40
babel-transform-legacy-decorators v1.3.0 bug
import autobind from './autobind';
class Base {
constructor(v) {
this.v = v;
}
}
function multiply(by) {
return function $multiply(target, name, descriptor) {
@elierotenberg
elierotenberg / statefulComponent.jsx
Last active March 3, 2016 23:41
Generator function as a stateful component
const willUnmount = Symbol('unmount');
function statefulComponent(getInitialState, render, componentWillUnmount = () => void 0) {
return function*(props) {
const internalId = React.pleaseGiveMeAnInternalId();
const state = getInitialState(props);
const setState = (nextState) => {
Object.assign(state, nextState);
React.pleaseRerenderThisInternalId(internalId);
};