Skip to content

Instantly share code, notes, and snippets.

/** @jsx React.DOM */
var MyRootComponent = React.createClass({
getInitialState: function() {
return {perMinute: '-', perDay: '-'};
},
componentDidMount: function() {
var socket = io.connect(this.props.url);
socket.on('business.clickout', this.setState.bind(this));
},
render: function() {
@ooade
ooade / AsyncComponent.jsx
Created January 21, 2017 10:30 — forked from scurker/AsyncComponent.jsx
Async Component in Preact
import { h, Component } from 'preact';
class AsyncComponent extends Component {
constructor() {
super();
this.state = { loading: true };
this.getAsyncState = this.getAsyncState.bind(this);
this.update = this.update.bind(this);
}
@ooade
ooade / split-point.js
Created January 17, 2017 09:45 — forked from developit/split-point.js
A couple of variants for preact split points
import { h, Component } from 'preact';
/**
* <SplitPoint load={require('bundle?lazy!./foo')} fallbackContent={(
* <div class="loading" />
* )} />
*/
class SplitPoint extends Component {
componentWillMount() {
let cb = this.linkState('child'),
@ooade
ooade / base64-image-upload.js
Last active September 2, 2016 20:18 — forked from madhums/base64-image-upload.js
save base64 encoded image
let fs = require('fs');
// string generated by canvas.toDataURL()
let img = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0"
+ "NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO"
+ "3gAAAABJRU5ErkJggg==";
// Grab the extension of the file
let ext = img.split(';')[0].match(/jpeg|png|gif/)[0];