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 { use, useEffect, useState } from "react"; | |
| export function createUseService<T>(loader: () => Promise<T>) { | |
| let state: number = 0; | |
| let listeners = new Set<(state: number) => void>(); | |
| let promise: Promise<T> | undefined; | |
| function listenToPromise(promise: Promise<T>) { | |
| state = 1; |
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
| /** | |
| * The command to see the animation: | |
| * curl localhost:3000 | |
| * | |
| * @see https://github.com/alexeyraspopov/picocolors/blob/main/picocolors.js | |
| * @see https://github.com/sindresorhus/ansi-escapes/blob/main/index.js | |
| * @see https://github.com/sindresorhus/cli-spinners | |
| */ | |
| import { Readable } from "node:stream"; | |
| import { fastify } from "fastify"; |
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 Component from '@ember/component'; | |
| export default Component.extend({ | |
| tagName: '', | |
| key: undefined, | |
| keys: Ember.computed('key', function () { | |
| return [{ | |
| key: String(this.get("key")) | |
| }]; | |
| }).readOnly(), |
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 class ScopedStorage implements Storage { | |
| [name: string]: any; | |
| #storage: Storage; | |
| #prefix: string; | |
| constructor(storage: Storage, prefix: string) { | |
| this.#storage = storage; | |
| this.#prefix = prefix; |
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 ResizeObserver from "resize-observer-polyfill"; | |
| import * as React from "react"; | |
| import ReactDOM from "react-dom"; | |
| type DOMRectReadOnly = ResizeObserverEntry["contentRect"]; | |
| const callbacks = new Map<Element, (_: DOMRectReadOnly) => void>(); | |
| const ro = new ResizeObserver(entries => { | |
| ReactDOM.unstable_batchedUpdates(() => { |
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 * as React from "react"; | |
| export function usePreviousValue<T>(value: T): T { | |
| const refPrevious = React.useRef(value); | |
| const refCurrent = React.useRef(value); | |
| if (refPrevious.current !== refCurrent.current) { | |
| refPrevious.current = refCurrent.current; | |
| } |
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
| function asArray(target) { | |
| if (!Immutable.List.isList(target)) { | |
| throw new TypeError("target is not Immutable.List"); | |
| } | |
| return new Proxy(new Array(target.size), { | |
| get(__, key, receiver) { | |
| if (typeof key !== "symbol") { | |
| const index = parseInt(key, 10); |
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 * as React from "react"; | |
| type RenderT<State> = ( | |
| state: State, | |
| update: <K extends keyof State>(key: K, value: State[K]) => void, | |
| ) => React.ReactNode; | |
| interface Props<State> { | |
| state: State; | |
| render: RenderT<State>; |
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
| <body onload=' | |
| K = onkeydown = ({ keyCode: k }) => { | |
| if (k > 36 && k < 41) { | |
| ox = (k -= 38)==2?0:k; | |
| oy = k==-1?0:k-1; | |
| A = M[y][x]; | |
| B = M[y + oy][x + ox] || "#"; | |
| C = (Y=M[y + oy * 2]||[])[x + ox * 2]; | |
| a = A == "+" ? "." : " "; |
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
| var obj = { | |
| _fooValue: 1, | |
| _fooGetterShouldReturnThis: false, | |
| get foo() { | |
| var value = this._fooGetterShouldReturnThis ? this : this._fooValue; | |
| this._fooGetterShouldReturnThis = false; | |
| return value; | |
| }, |
NewerOlder