You all know that to create a new Promise you need to define it this way:
new Promise((resolve, reject) => {
...
resolve(someValue)
})
You are passing a callback that defines the specific behavior of your promise.
export class PromiseQueue<T> { | |
readonly concurrency: number; | |
#ongoingPromisesCount: number; | |
#toRun: Array<() => Promise<T>>; | |
constructor({ concurrency = 1 } = {}) { | |
this.concurrency = concurrency; | |
this.#ongoingPromisesCount = 0; | |
this.#toRun = []; | |
} |
type TextMarks = | |
| { type: "bold" } | |
| { type: "italic" } | |
| { type: "code" } | |
| { type: "strike" } | |
| { type: "textStyle"; attrs: Partial<CSSStyleDeclaration> } | |
| { | |
type: "link"; | |
attrs: { | |
href: string; |
export type TaskPriority = "user-blocking" | "user-visible" | "background"; | |
export type SchedulerPostTaskOptions = { | |
// This priority is immutable and overrides the | |
// TaskController's priority. | |
priority?: TaskPriority; | |
delay?: number; | |
signal?: TaskSignal; | |
}; |
import { createLiveState, crdtSchema } from "@/lib/live-state"; | |
export type NotebookJSON = { | |
title: string; | |
description: string; | |
cells: TextCell[]; | |
}; | |
const notebookCRDTSchema = { | |
title: crdtSchema.LiveText(), |
import mapValues from 'lodash/mapValues'; | |
export type Step<Anims> = { | |
[K in keyof Anims]: { value: number; progress: number }; | |
}; | |
export type Values<Anims> = { [K in keyof Anims]: number }; | |
export interface SpringOptions { | |
/** |
type RafState<Args> = | |
| { type: 'waiting'; latestArgs: Args; rafId: number } | |
| { type: 'idle' }; | |
export const animationFrameThrottle = <Args extends any[]>( | |
callback: (...args: Args) => unknown, | |
): ((...args: Args) => void) & { cancel: () => void } => { | |
let state: RafState<Args> = { type: 'idle' }; | |
const cancel = () => { |
/* ----------------------------------------- * | |
Lazy List Implementation | |
* ----------------------------------------- */ | |
// Haskell-like infinite List, implemented with es6 generators | |
// Lazyness lets you do crazy stuff like | |
List.range(0, Infinity) | |
.drop(1000) | |
.map(n => -n) |
export function usePrevious<T>(value: T): T | undefined { | |
const ref = React.useRef<T>(); | |
React.useEffect(() => { | |
ref.current = value; | |
}); | |
return ref.current; | |
} |
useEffect(() => {
})
<>
<Child log1 />
{console.log("log3")}
<Child log2 />
>