Skip to content

Instantly share code, notes, and snippets.

@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 / react-terminology.md
Created November 22, 2016 08:55 — forked from sebmarkbage/react-terminology.md
React (Virtual) DOM Terminology
@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 / 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 / draftjs-create-blocks-with-Image.js
Created December 23, 2016 08:19
Create draftjs blocks with images
const createBlocksWithImage = ()=>{
const url = "https://www.google.es/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png";
const entityKey = Entity.create( 'image', 'IMMUTABLE', { src: url } );
const charData = CharacterMetadata.create({ entity: entityKey })
const blockSpec = {
type : 'atomic',
text : ' ',
key: genKey(),
depth: 0,
characterList: List(Repeat(charData, 1))
@tomcask
tomcask / draftjs-initial-state.js
Created December 23, 2016 08:22
Example of initial state with image
const initialState = {
"entityMap": {
"0": {
"type": "image",
"mutability": "MUTABLE",
"data": {
"src": "https://www.google.es/images/branding/googlelogo/2x/googlelogo_color_120x44dp.png"
}
}
},
@tomcask
tomcask / draftjs-force-selection.js
Created January 10, 2017 16:52
Example of force selection in draftjs
const getEditorState = this.props.store.getItem('getEditorState');
const setEditorState = this.props.store.getItem('setEditorState');
const selection = this.props.store.getItem('lastSelection');
const editorState = getEditorState();
const updateSelection = new SelectionState({
anchorKey: selection.anchorKey,
anchorOffset: selection.anchorOffset,
focusKey: selection.anchorKey,
focusOffset: selection.focusOffset,
isBackward: false,
@tomcask
tomcask / partiasl-templates-hbs.js
Created January 20, 2017 12:02
Using partials are templates that can be reused in other templates with hbs.
//http://danburzo.ro/grunt/chapters/handlebars/
//In templating languages, partials are templates that can be reused in other templates. In Handlebars, you use the {{> partial }} helper to include partials. Let's take an example:
//Note: It's important to register the partial before compiling any template that includes it, otherwise it will throw an error.
<script type='text/x-handlebars' id='post-list-template'>
<h2>{{ title }}</h2>
<ul>
{{#each posts}}
<li>{{> post-item}}</li>
{{/each}}
@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 / 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;
}