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 { useRef, useEffect, useCallback } from 'react'; | |
import Split, { SplitOptions, SplitInstance } from 'split-grid'; | |
export function useSplitGrid(options: SplitOptions): SplitInstance | undefined { | |
const splitInstance = useRef<SplitInstance>(); | |
useEffect(() => { | |
const split = Split(options); | |
splitInstance.current = split; | |
return () => split.destroy(); |
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
/** | |
* Iterate a string runes. Same as iterating [...str] | |
* | |
* Note: This assume that the string is well-formed | |
* | |
* WARNING: This is useless, use the string iterator. | |
*/ | |
export function* runeIterator(s: string) { | |
const len = s.length; | |
let highSurrogate: number | undefined; |
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
/** | |
* Simulate a 'scrollstart' and 'scrollend' event by listening to scroll and debouncing the calls. | |
* | |
* The proposal to standardize part of this is https://github.com/w3c/csswg-drafts/issues/3744 | |
*/ | |
export function useScrollStartEndEvents( | |
ref: RefObject<HTMLElement>, | |
onScrollStart?: () => void, | |
onScrollEnd?: () => void, | |
debounceTimeMs: number = 100 |
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
/* eslint-disable @typescript-eslint/no-unsafe-return */ | |
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | |
function deepReferentialEquality(from: any, to: any, path = ''): any { | |
if (to === undefined || from === undefined || to === null || from === null) { | |
return to; | |
} | |
const objectType = typeof from; | |
if (objectType !== typeof to) { | |
// The object changed type |
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 { Queue } from 'src/utils/queue'; | |
import { assertDefined } from 'src/utils/asserts'; | |
interface QueueItem { | |
readonly generator: () => PromiseLike<any>; | |
readonly resolve: (value: any) => void; | |
readonly reject: (error: any) => void; | |
} | |
interface PerKeyQueue<TKey> { |
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
/* eslint-disable @typescript-eslint/unbound-method */ | |
/* eslint-disable no-param-reassign */ | |
import zlib from 'zlib'; | |
import concatStream from 'concat-stream'; | |
import BufferHelper from 'bufferhelper'; | |
import stream from 'stream'; | |
import { IncomingMessage, ServerResponse } from 'http'; | |
export type Modification = (original: string, proxyRes: IncomingMessage) => string | undefined; |
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 { Iterable, Map } from "immutable"; | |
// tslint:disable:array-type | |
// tslint:disable:unified-signatures | |
export interface Immutable<T> { | |
set<TKey extends keyof T>(key: TKey, value: T[TKey]): Immutable<T>; | |
/** | |
* Returns a new Map which excludes this `key`. | |
* |
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
// Flawed try, I don't think a deep function ignoring compare is practical | |
// | |
// https://fable.io/repl/#?code=PYBwpgdgBAYghgIwDZgHQEkC2JgCcAuqAUgMoCwAUKJLIiqgMJ5pEDO6E+Yuol108ZGia4wlSgG0APFhwEAFACIwARwCucJAEFcuOAE9WAdQCW+ABaKANFEUAzOmAC0SEwj259AegCq+E0ioAFasigCUAHwAupQo+FAguCYAbnBcUKoa2roGxmbmUPIAHgBcUMAIQWGF+mUVVYUAxth1lVBOEeVtHVAIwMBIYWV9A1AAvJRQU1AhAHJpKWIUkjLYePhKjcDYcKIAImlgoTb2ji5uHt5+AcGhkTEUcQlJqelbO-uHrIWlXQ3ytT+QygJk440m0zmC2SSxWAFFMGYlAASAAM4zGUGRAEZwtFYmB4okUocZqw4epNN9ilBWv99LSgYyRkhxmT5v4YeIKNIEUjFGioABCTE4vEPJ7E15gdnAfAUrLUoqM+rVAEqyrVYb9VmYqGc2GPQnPEnpVhwTBgAAq+nAPzpasBqvBFGmsvllKQ3wZEDUSFZADIAxC3VN6qgAEpgOzcSCNMAKqnyEOht0AeUqYEahAA5oSAAo8fBy21gNN2YphAD8WwgrHwuDU2bwVhTqamGaCWdzBaLJfA5YB1dr9cbzdwYW5vMRG0U+FLwDsWNR4oJRJepJCNvAi8KAH0NQ0yqPQTm2frFlOpHzZ4LQfW4BB47uDlxV0b16aZSZWK+ZfIDwdZkdXPVgOUvZYPxBCBXAgGUpVJH8dD0BliiAiZXWmZCDFQJCcgZZUAB9CKgbD9AAITUOwY1wXDWAANRMMAAHcoCKblJQ3dJRC2XAABNCzlfsZQw9NM2zVA83wQTi3nAcKwAbxIzBdgAa24NkGzUGVCIAX0nSCnh4k1pRBVgo14vj7SZUTphMJcQkTL02KgX1-SgCxIDbaYHC9JY3TAPzvKmTih |
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
export class Test extends React.PureComponent<{}, {}> { | |
UNSAFE_componentWillUpdate(nextProps: any, nextState: any) { | |
const changedProps = _.reduce( | |
this.props, | |
(result: string[], value, key) => value === nextProps[key] ? result : result.concat(key), | |
[]); | |
console.log("changedProps: ", changedProps); | |
const changedStates = _.reduce( | |
this.state, | |
(result: string[], value, key) => value === nextState[key] ? result : result.concat(key), |
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
module MemoReactHelpers | |
/// A special ReactElement that tell React to not render anything | |
[<Emit("null")>] | |
let noElement = jsNative<ReactElement> | |
[<Erase>] | |
type ComponentClass<'props, 'state> = class end | |
[<RequireQualifiedAccess>] |
NewerOlder