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
export type JsonPrimitive = null | boolean | number | string; | |
export type JsonArray = Array<JsonValue>; | |
export type JsonObject = { [key: string]: JsonValue }; | |
export type JsonValue = JsonPrimitive | JsonArray | JsonObject; |
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
export function useStableCallback<T extends Array<unknown>, R>( | |
callback: (...args: T) => R, | |
): (...args: T) => R { | |
let ref = useRef(callback); | |
useLayoutEffect(() => { | |
ref.current = callback; | |
}); | |
let stableCallback = useCallback((...args: T) => { | |
return ref.current(...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
// node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js | |
"use strict"; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.default = void 0; | |
function _helperPluginUtils() { |
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
type Listener<T extends Array<unknown>> = (...args: T) => void; | |
export class EventEmitter< | |
E extends Record<string, Array<unknown>> = Record<never, []> | |
> { | |
private listenerMap: { [K in keyof E]?: Set<Listener<E[K]>> } = {}; | |
on<K extends keyof E>(key: K, listener: Listener<E[K]>) { | |
return this.addListener(key, listener); | |
} |
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
{ | |
"jest": { | |
"preset": "jest-expo", | |
"transform": { | |
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js", | |
"^.+\\.tsx?$": "ts-jest" | |
}, | |
"testMatch": [ | |
"**/__tests__/**/*.ts?(x)", | |
"**/?(*.)+(spec|test).ts?(x)" |
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
// @flow | |
import fs from 'fs'; | |
import {join} from 'path'; | |
async function main() { | |
let filePath = join(__dirname, '../assets/image.jpg'); | |
// The first one uses Promise-based readable stream. | |
await getFileSizeOne(filePath); | |
// The second one uses "for await" async iterator approach. | |
await getFileSizeTwo(filePath); |
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
// @flow | |
/* global fetch */ | |
/* eslint-disable babel/no-await-in-loop */ | |
type JSONData = null | string | number | boolean | {[key: string]: JSONData} | Array<JSONData>; | |
function handleResponseJSON(response: Response): Promise<JSONData> { | |
return response.json(); | |
} |
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 './App.css'; | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.state = { | |
error: null, | |
data: null, | |
}; |
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 http = require('http'); | |
let server = http.createServer(); | |
server.on('request', (request, response) => { | |
let {method, url, headers} = request; | |
console.log(`Received ${method} request for "${url}".`); | |
for (let headerName of Object.keys(headers)) { | |
let headerValue = headers[headerName]; |
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
// ES5 | |
var getBound = Function.prototype.apply.bind(Function.prototype.bind) | |
function createDate() { | |
for (var i = 0, length = arguments.length, args = new Array(length + 1); i < length; i++) { | |
args[i + 1] = arguments[i]; | |
} | |
var BoundDate = getBound(Date, args); | |
return new BoundDate(); |