Skip to content

Instantly share code, notes, and snippets.

View YurkaninRyan's full-sized avatar

Ryan Yurkanin YurkaninRyan

View GitHub Profile
const numbers = [
38,
54,
68,
93,
72,
12,
33,
8,
98,
@YurkaninRyan
YurkaninRyan / useClickOutside.js
Created July 10, 2019 12:48
useClickOutside
import React from "react";
export default function useClickOutside(onClickOutside, exempt = []) {
const container = React.useRef(null);
const mouseDownTargetIsOutside = React.useRef(false);
React.useEffect(() => {
/* if the click event doesnt start outside of the element then we want to ignore it */
/* imagine if someone clicked while swiping the cursor, if it started inside, then they probably */
/* wouldn't expect mouseup to fire like it was outside */
const fetch = new Effect();
function double() {
const x = fetch.throw("number");
return x * 2
}
try {
double()
} fetch.catch(resume, ...args) {
function double(x) {
if (!Number.isFinite(x)) {
return console.error(
`double(x): ${x} is not a number`
)
}
return x * 2
}
function double(x, opts) {
if (!Number.isFinite(x)) {
const error = `double(x): ${x} is not a number`;
if (opts.onError) {
return opts.onError(error)
}
return console.error(error)
}
import double from "./double";
// How were we supposed to know we get a second argument
// that has an onError function?
function doublePlusOne(x) {
// if double isn't a number, it will return a string!
return double(x) + 1;
}
import double from "./double";
function doublePlusOne(x, opts) {
// Can't forget to pipe our "opts" through!
const doubled = double(x, opts);
// We must of received an error.
if (!Number.isNumber(doubled)) { return null; }
return doubled + 1;
function double(x) {
if (!Number.isFinite(x)) {
throw `double(x): ${x} is not a number`;
}
return x * 2
}
// We don't have to be aware anymore!
function doublePlusOne(x) {
import React from "react";
import ReactDOM from "react-dom";
/* This hook is just a simple cache for computing initial state */
function useOnce(func) {
const used = React.useRef("NOT_USED");
if (used.current === "NOT_USED") {
used.current = func();
}
function init(userConfig) {
const DEFAULT_CONFIG = {
removeSpaces: false,
allowHighlighting: true,
priority: "high",
}
const config = { ...DEFAULT_CONFIG, ...userConfig };
}