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 MINUTE = 1000 * 60; | |
function asyncCachedFn<Args extends any[], Result>(options: { | |
fn: (...args: Args) => Promise<Result>; | |
key: (...args: Args) => string; | |
}) { | |
const cache: Map< | |
string, | |
{ computedAt: number; evict: any; result: Promise<Result> } |
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
// regexes to remove lines from thrown error stacktraces | |
const AT_NODE_INTERNAL_RE = /^\s*at.+node:internal.+/gm; | |
const AT_TYPES_INTERNAL_RE = /^\s*at.+\/types\/src\/.+/gm; | |
const AT_INVARIANT_RE = /^\s*(at|[^@]+@) (?:Object\.)?invariant.+/gm; | |
const AT_INVARIANT_MORE_RE = /^\s*at.+(?:invariant|asError|createErrorObj).+/gm; | |
const AT_TEST_HELPERS_RE = /^\s*(at|[^@]+@).+test\-helpers.+/gm; | |
// const AT_WEB_MODULES = /^\s*(at|[^@]+@).+(web_modules|\-[a-f0-9]{8}\.js).*/gm | |
const AT_ASSORTED_HELPERS_RE = | |
/^\s*(at|[^@]+@).+(debounce|invariant|iife)\.[tj]s.*/gm; |
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 { Slot, component$ } from "@builder.io/qwik"; | |
import type { JSX } from "@builder.io/qwik/jsx-runtime"; | |
import { twMerge } from "tailwind-merge"; | |
/** Comes from {@link tw} template. */ | |
type TwString = string & { | |
_tw: true; | |
}; | |
/** This applies types to somethign like `tw.div` or `tw.h1`, which will leverage the types from `JSX.IntrinsicElements` */ |
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 type { NoSerialize, Signal } from "@builder.io/qwik"; | |
import { noSerialize, useSignal, useVisibleTask$ } from "@builder.io/qwik"; | |
import type { IFuseOptions } from "fuse.js"; | |
import Fuse from "fuse.js"; | |
export function useFuseSearch<T>( | |
config: { | |
items: Signal<T[]> | T[]; | |
search: Signal<string> | string; | |
}, |
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 type { Readable } from "svelte/store"; | |
const UNSET = Symbol(); | |
export function read<T>(store: Readable<T>): T { | |
let value: T | typeof UNSET = UNSET; | |
store.subscribe((v) => (value = v))(); | |
if (UNSET === value) { | |
throw new Error("Readable did not react synchronously"); | |
} | |
return value; |
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 ChangeNotifier { | |
callbacks: Array<() => void> = []; | |
onChange(callback: () => void) { | |
this.callbacks.push(callback); | |
return () => { | |
const index = this.callbacks.indexOf(callback); | |
if (index >= 0) { | |
this.callbacks.splice(index, 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
export interface IDisposable { | |
dispose(): void; | |
} | |
export class DisposePool implements IDisposable { | |
#fns: null | (() => void)[] = []; | |
#pool: null | IDisposable[] = []; | |
get disposed() { | |
return this.#pool === 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
import { | |
Object3D, PerspectiveCamera, Scene, | |
WebGLRenderer | |
} from "three"; | |
import { CleanupFn } from "./CleanupFn"; | |
import { DisposePool, isDisposable } from "./DisposePool"; | |
import { merge } from "./merge"; | |
import { ISheet } from "@theatre/core"; | |
import { TheatreMergeable, theatreMerge } from "./theatreMerge"; | |
import { EventsPool } from "./EventsPool"; |
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 jsReplacer() { | |
const seen = new WeakSet(); | |
return (key: string, value: any) => { | |
if (typeof value === "object" && value !== null) { | |
if (seen.has(value)) return "[Circular]"; | |
seen.add(value); | |
} | |
if (value instanceof RegExp) return { regexp: value.toString() }; | |
if (value instanceof Function) return { function: value.toString() }; | |
if (value instanceof Error) return { error: value.toString() }; |