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 memoize(_target: object, _key: string, descriptor: PropertyDescriptor) { | |
const cache = {}; | |
const original = descriptor.value; | |
descriptor.value = async function(...args: any[]) { | |
const argsStr = JSON.stringify(args); | |
cache[argsStr] = cache[argsStr] || original.apply(this, args); | |
return cache[argsStr]; | |
}; |
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
find src -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \; |
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
// Like array.map, but for objects | |
const mapObj = <U, T extends object>( | |
obj: T, | |
mapFn: (val: T[keyof T], key?: keyof T) => U | |
): { [K in keyof T]: U } => { | |
return Object.assign( | |
{}, | |
...Object.entries(obj).map(([k, v]) => ({ [k]: mapFn(v, k as keyof T) })) | |
); | |
}; |
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
// Like Promise.all, but for objects of {key: Promise} | |
const promsieAllObj = async <T>(obj: Record<string, Promise<T>>): Promise<Record<string, T>> => { | |
const arr = Object.entries(obj).map(([key, value]) => value.then(res => [key, res])); | |
return Object.assign( | |
{}, | |
...(await Promise.all(arr).then(res => res.map(([k, v]) => ({ [k as string]: v as T })))) | |
); | |
}; |
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
{ | |
"React Component": { | |
"prefix": "rcc", | |
"body": [ | |
"import * as React from 'react'", | |
"", | |
"export interface ${1:IApp}Props {", | |
" ${2:}", | |
"}", | |
"", |