Skip to content

Instantly share code, notes, and snippets.

@tomcask
tomcask / 0. intro.md
Created March 15, 2017 07:59 — forked from jquense/0. intro.md
Alternative ways to define react Components

The 0.13.0 improvements to React Components are often framed as "es6 classes" but being able to use the new class syntax isn't really the big change. The main thing of note in 0.13 is that React Components are no longer special objects that need to be created using a specific method (createClass()). One of the benefits of this change is that you can use the es6 class syntax, but also tons of other patterns work as well!

Below are a few examples creating React components that all work as expected using a bunch of JS object creation patterns (https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/ch4.md#mixins). All of the examples are of stateful components, and so need to delegate to React.Component for setState(), but if you have stateless components each patterns tends to get even simpler. The one major caveat with react components is that you need to assign props and context to the component instance otherwise the component will be static. The reason is

@tomcask
tomcask / function.prototype.override.js
Created March 15, 2017 07:59 — forked from pentaphobe/function.prototype.override.js
How to override the function call prototype in javascript, originally a stack overflow answer
callLog = [];
/* set up an override for the Function call prototype
* @param func the new function wrapper
*/
function registerOverride(func) {
oldCall = Function.prototype.call;
Function.prototype.call = func;
}
@tomcask
tomcask / chrome_monitorEvents.md
Created February 1, 2017 15:34 — forked from WillSquire/chrome_monitorEvents.md
Chome monitorEvents

Monitor events by ID:

monitorEvents(document.getElementById('id'))

Monitor events by class:

monitorEvents(document.querySelector('.class'))
@tomcask
tomcask / destructuring.js
Created December 5, 2016 10:15 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@tomcask
tomcask / export-syntax.js
Created December 1, 2016 14:36 — forked from caridy/export-syntax.js
ES6 Module Syntax Table
// default exports
export default 42;
export default {};
export default [];
export default foo;
export default function () {}
export default class {}
export default function foo () {}
export default class foo {}
@tomcask
tomcask / react-terminology.md
Created November 22, 2016 08:55 — forked from sebmarkbage/react-terminology.md
React (Virtual) DOM Terminology
@tomcask
tomcask / Enhance.js
Created November 22, 2016 08:54 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@tomcask
tomcask / .gitconfig
Last active November 4, 2016 12:24 — forked from shawndumas/.gitconfig
Using WinMerge as the git Diff/Merge Tool on Windows 64bit
[mergetool]
prompt = false
keepBackup = false
keepTemporaries = false
[merge]
tool = winmerge
[mergetool "winmerge"]
name = WinMerge
@tomcask
tomcask / DropboxIgnore.md
Created November 3, 2016 23:09 — forked from idleberg/DropboxIgnore.md
Ignore node_modules/bower_components folders in your Dropbox

This script scans your Dropbox (or any given folder) for folders stored in the ignore array and excludes them from syncing. Makes use of the official Dropbox CLI

I'm a beginner at bash, so all improvements are welcome!

#!/bin/bash

set -e

# SETTINGS