diff options
author | 2025-08-14 17:40:40 +0200 | |
---|---|---|
committer | 2025-08-14 17:40:40 +0200 | |
commit | 02e56b0f3ede24c45c35ea4d0a1981dab42837a2 (patch) | |
tree | 3b3a1e1a3853f3085a792ba60817919b26c58970 /src | |
parent | bacf9cf38388c32244768845b347dfb907dcd419 (diff) | |
download | videotool-02e56b0f3ede24c45c35ea4d0a1981dab42837a2.tar.gz videotool-02e56b0f3ede24c45c35ea4d0a1981dab42837a2.tar.bz2 videotool-02e56b0f3ede24c45c35ea4d0a1981dab42837a2.tar.lz videotool-02e56b0f3ede24c45c35ea4d0a1981dab42837a2.zip |
feat: lazycell
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/vendor/lazy-cell/index.ts | 1 | ||||
-rw-r--r-- | src/lib/vendor/once-cell/index.ts | 94 |
2 files changed, 1 insertions, 94 deletions
diff --git a/src/lib/vendor/lazy-cell/index.ts b/src/lib/vendor/lazy-cell/index.ts new file mode 100644 index 0000000..c38445c --- /dev/null +++ b/src/lib/vendor/lazy-cell/index.ts @@ -0,0 +1 @@ +export * from 'https://codeberg.org/dmpmem/js-lazycell/raw/commit/1b68e36e5de94d6202eee41f9cf122bcee196a2e09d8b0cdaf82e1767b1d9328/mod.ts' diff --git a/src/lib/vendor/once-cell/index.ts b/src/lib/vendor/once-cell/index.ts deleted file mode 100644 index 5ae37f0..0000000 --- a/src/lib/vendor/once-cell/index.ts +++ /dev/null @@ -1,94 +0,0 @@ -export type Proxy<T> = T; -export type OnceCell<T> = Proxy<T & { - /** - * Do not use. - * @deprecated Implementation Detail. - * @internal @private @ignore - */ - '*internal.oncecelldereference': T -}>; -export type OnceCellConstructor = Proxy<(<T>(create: () => T) => Proxy<T>) & (new <T>(create: () => T) => OnceCell<T>) & { - dereference: <T>(cell: OnceCell<T>) => T -}>; -/** - * @license MIT - * @copyright memdmp <memdmp@estrogen.zone> - */ -export const OnceCell = new Proxy( - // We use the function keyword here to indicate that this *may* be a constructor - function <T>(create: () => T): OnceCell<T> { - if (typeof create !== 'function') throw new Error('Must pass function to OnceCell') - let createOnce = (): T extends object ? T : never => { - const t = create(); - return (createOnce = () => t as T extends object ? T : never)() - } - const onceCellProxyImplementation: ProxyHandler<{ - get value(): T - }> = { - get(_, idx, receiver) { - const target = createOnce(); - if (idx === '*internal.oncecelldereference') return target; - // .valueOf() and similar prototype methods should be proxied properly - if (!Object.hasOwnProperty.call(target, idx) && typeof target[idx as keyof T] === 'function') { - return (...args: unknown[]) => { - // @ts-expect-error we don't know .call's argument types, so we just hope and pray they're good and leave it to the caller to deal with it if it isn't - return target[idx as keyof T].call(target, args); - } - } - // return Reflect.get(obj, idx, receiver) - return target[idx as keyof T]; - }, - set(_, ...args) { - return Reflect.set(createOnce(), ...args) - }, - has(_, idx, ...args) { - if (idx === '*internal.oncecelldereference') return true // to comply with the OnceCell type declaration's meaning - return Reflect.has(createOnce(), idx, ...args) - }, - deleteProperty(_, ...args) { - return Reflect.deleteProperty(createOnce(), ...args) - }, - isExtensible(_, ...args) { - return Reflect.isExtensible(createOnce(), ...args) - }, - ownKeys(_, ...args) { - return Reflect.ownKeys(createOnce(), ...args) - }, - defineProperty(_, ...args) { - return Reflect.defineProperty(createOnce(), ...args) - }, - getOwnPropertyDescriptor(_, ...args) { - return Reflect.getOwnPropertyDescriptor(createOnce(), ...args) - }, - preventExtensions(_, ...args) { - return Reflect.preventExtensions(createOnce(), ...args) - }, - getPrototypeOf(_, ...args) { - return Reflect.getPrototypeOf(createOnce(), ...args) - }, - setPrototypeOf(_, ...args) { - return Reflect.setPrototypeOf(createOnce(), ...args) - }, - apply(_, ...args) { - type F = (this: any, ...args: any[]) => any - return Reflect.apply(createOnce() as unknown as T extends F ? F : never, ...args) - }, - construct(_, ...args) { - type F = (this: any, ...args: any[]) => any - return Reflect.construct(createOnce() as unknown as T extends F ? F : never, ...args) - }, - } - return new Proxy({ - /** For debuggers */ - get value() { - return createOnce() - } - }, onceCellProxyImplementation) as unknown as OnceCell<T> - }, { - construct(onceCellCreationFunction, argArray, newTarget) { - return onceCellCreationFunction(argArray[0]) - }, -}) as OnceCellConstructor -OnceCell.dereference = (t) => Reflect.get(t as object, '*internal.oncecelldereference', t) -Object.freeze(OnceCell) -export default OnceCell |