Skip to content

Instantly share code, notes, and snippets.

View bebraw's full-sized avatar

Juho Vepsäläinen bebraw

View GitHub Profile
@eldh
eldh / breakpoint-mixin.coffee
Last active August 29, 2015 14:19
React breakpoints mixin
Style = require '../styles/props'
_ = require 'lodash'
module.exports =
_setScreenWidth: ->
if @isMounted() then @setState {screenWidth: window.innerWidth}
getInitialState: -> screenWidth: window?.innerWidth or 1280
screenWidth: (minName, maxName) ->
@gaearon
gaearon / Stateful.js
Created April 23, 2015 16:57
Stateful.js
import React, { Component } from 'react';
// Usage:
//
// @Stateful({
// initialize(props) {
// return {
// count: 0
// };
// },
@eldh
eldh / InViewWrapper.coffee
Created April 24, 2015 08:30
react-in-view
module.exports = React.createClass
displayName: 'InViewWrapper'
propsTypes:
onInView: React.PropTypes.func.isRequired
inViewOffset: React.PropTypes.number
getDefaultProps: ->
inViewOffset: 0
@mjackson
mjackson / AutoBindingComponent.js
Created May 6, 2015 20:35
A React.Component subclass that mimics 0.12's auto-binding behavior
var React = require('react');
class AutoBindingComponent extends React.Component {
constructor(props) {
super(props);
for (var property in this) {
if (this.hasOwnProperty(property) && typeof this[property] === 'function') {
this[property] = this[property].bind(this);
}
@goatslacker
goatslacker / transforms-with-alt.js
Last active August 29, 2015 14:20
Nuclear-style transforms for Alt stores
import Alt from './'
// the magic sauce
import { createTransform } from './utils/frp'
// decorator utilities
import { createStore, bind } from './utils/decorators'
const alt = new Alt()
module.exports = React.createClass({
displayName : 'LazyRender',
getInitialState() { return { props : this.props } },
componentWillReceiveProps(newProps) { setTimeout(() => this.setState(newProps), 10) },
shouldComponentUpdate(newProps, newState) { return this.state !== newState; },
render() { return React.cloneElement(React.Children.only(this.props.children), this.state); }
});
import React, {Component} from 'react';
import request from 'superagent-bluebird-promise';
class AjaxGet extends Component {
constructor(props, context) {
super(props, context);
this.state = {
data: {}
};
@ryanflorence
ryanflorence / logtime.js
Created January 4, 2012 16:26
Log the time of JS operations
var logtime = (function() {
var ids = {};
return function(id) {
if (!ids[id]) {
ids[id] = +new Date();
return;
}
var time = +new Date() - ids[id];
@mattpodwysocki
mattpodwysocki / main.html
Created September 13, 2012 05:16
RxJS + Require.JS
<!DOCTYPE html>
<html>
<head>
<title>RequireJS</title>
<script data-main="scripts/main" src="scripts/require.js"></script>
</head>
<body>
<div id="coordinates">0,0</div>
<div id="delta">0</div>
<ul id="buffer"></ul>
@jquense
jquense / jsx-mode.js
Last active October 17, 2015 05:40
An attempt at a jsx CodeMirror mode
/*global CodeMirror */
function indexOf(string, pattern, from) {
if (typeof pattern === "string") {
var found = string.indexOf(pattern, from);
return found;
}
var m = pattern.exec(from ? string.slice(from) : string);
return m ? (m.index + from) : -1;
}