This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createElement(tag, props, ...children) { | |
return ( | |
`<${tag}${renderProps(props)}>${children.join ? children.join('') : children}</${tag}>` | |
) | |
} | |
function renderProps(props) { | |
const propsString = Object.keys(props).map(key => `${key}="${props[key]}"`).join(' ') | |
return propsString ? ' ' + propsString : '' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { renderToString } from 'react-dom/server' | |
import Menu from './Menu' | |
const SELECTOR = '#test-component' // or whatever | |
class Component extends React.Component { | |
state = { html: { __html: "" } } | |
componentDidMount() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flip(fn) { | |
return function () { | |
return fn.apply(null, Array.prototype.reverse.call(arguments)) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function curry(fn, ...initialArgs) { | |
return function (...nextArgs) { | |
const args = initialArgs.concat(nextArgs) | |
if (args.length >= fn.length) { | |
return fn(...args) | |
} | |
return curry(fn, ...args) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { render } from 'react-dom'; | |
class Child extends React.Component { | |
componentDidMount() { | |
if (this.props.n === 0) { | |
console.log(`child mounted at ${Date.now()}`) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum(xs) { | |
return xs.reduce((total, x) => total + x, 0) | |
} | |
function mean(xs) { | |
return sum(xs) / xs.length | |
} | |
function zip(xs, ys) { | |
return range(xs.length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require("assert") | |
function pipes(func) { | |
return function () { | |
const value = func.apply(null, arguments) | |
return { | |
value, | |
pipe(func2) { | |
return func2(value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var el = document.createElement("div"); | |
document.body.innerHTML = ""; | |
document.body.appendChild(el); | |
document.body.addEventListener("foobar", announce); | |
el.addEventListener("foobar", preventBubble(announce)); | |
var event = new CustomEvent("foobar", { bubbles: true, detail: "Hello" }); | |
el.dispatchEvent(event); // "ANNOUNCING: Hello" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { wrapInQuotemarks, stripQuotationMarks, noop } from "./utils"; | |
let previousQuote = null; | |
export default class QuotationWrappedInput extends React.Component { | |
static defaultProps = { | |
InputComponent: ({ handleRef, ...props }) => <textarea ref={handleRef} {...props} />, | |
handleRef: noop, | |
maxLength: 320, | |
placeholder: "Type here", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callWith() { | |
const args = arguments | |
return function (fn) { | |
return fn.apply(null, args) | |
} | |
} | |
const add = d => x => x + d | |
const updaters = [add(1), add(2), add(3)] | |
console.log(updaters.map(callWith(10))) // [11, 12, 13] |