This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" | |
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> |
This file contains 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, {PureComponent} from 'react' | |
class Boundary extends PureComponent<any, any> { | |
static getDerivedStateFromError(error: any) { | |
return {hasError: true, error: error.toString()} | |
} | |
state = { | |
hasError: false, | |
error: '', |
This file contains 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
declare namespace Tag { | |
const OpaqueTagSymbol: unique symbol; | |
class OpaqueTag<S extends symbol> { | |
private [OpaqueTagSymbol]: S; | |
} | |
export type OpaqueType<T, S extends symbol> = T & OpaqueTag<S>; | |
} | |
export declare type Opaque<T, S extends symbol> = Tag.OpaqueType<T, S>; |
This file contains 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
class Observer { | |
#initialValue; | |
#subscriptions = []; | |
constructor(initialValue) { | |
this.#initialValue = initialValue; | |
} | |
subscribe(fn) { | |
this.#subscriptions.push(fn); |
This file contains 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(n, s = 0) { | |
return (n) ? () => sum(n - 1, s + n) : s | |
} | |
function trampoline(fn) { | |
return function (...args) { | |
let res = fn.apply(null, args) | |
while (typeof res === 'function') { | |
res = res() | |
} |
This file contains 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 memo = (function () { | |
const cache = new Map() | |
return function (fn, ctx = null, ...params) { | |
if (cache.has([fn, params, ctx].toString())) { | |
return cache.get([fn, params, ctx].toString()) | |
} else { | |
const res = fn.call(ctx, ...params); | |
cache.set([fn, params, ctx].toString(), res); | |
return res; | |
} |
This file contains 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 testExecutor(value) { | |
const A = function (x) { | |
this.value = x; | |
this.success = false; | |
}; | |
A.prototype.toBe = function (x) { | |
if (JSON.stringify(x) === JSON.stringify(this.value) && typeof this.value === typeof x) { | |
this.success = true; | |
console.log(`%cPassed: ${JSON.stringify(x)} equals ${JSON.stringify(this.value)}`, 'color: green;'); |