mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
chore(packages): remove isolatedDeclarations for store type inference support (#295)
This commit is contained in:
@@ -1,17 +1,10 @@
|
||||
/**
|
||||
* Request an animation frame and return a cleanup function to cancel it.
|
||||
*
|
||||
* @param callback - The callback to invoke on the next animation frame
|
||||
* @returns A cleanup function that cancels the animation frame request
|
||||
* Request an animation frame with cleanup.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const cancel = animationFrame((time) => {
|
||||
* console.log('Frame at', time);
|
||||
* });
|
||||
*
|
||||
* // Later, cancel if needed
|
||||
* cancel();
|
||||
* const cancel = animationFrame((time) => console.log('Frame at', time));
|
||||
* cancel(); // Cancel if needed
|
||||
* ```
|
||||
*/
|
||||
export function animationFrame(callback: FrameRequestCallback): () => void {
|
||||
|
||||
@@ -10,10 +10,10 @@ export interface OnEventOptions extends AddEventListenerOptions {
|
||||
/**
|
||||
* Wait for an event to occur on a target.
|
||||
*
|
||||
* @param target - The event target (HTMLMediaElement)
|
||||
* @param type - The event type to wait for
|
||||
* @param options - Optional event options including AbortSignal
|
||||
* @returns A promise that resolves with the event
|
||||
* @example
|
||||
* ```ts
|
||||
* const event = await onEvent(video, 'seeked');
|
||||
* ```
|
||||
*/
|
||||
export function onEvent<K extends keyof HTMLMediaElementEventMap>(
|
||||
target: HTMLMediaElement,
|
||||
@@ -21,79 +21,24 @@ export function onEvent<K extends keyof HTMLMediaElementEventMap>(
|
||||
options?: OnEventOptions,
|
||||
): Promise<HTMLMediaElementEventMap[K]>;
|
||||
|
||||
/**
|
||||
* Wait for an event to occur on a target.
|
||||
*
|
||||
* @param target - The event target (HTMLElement)
|
||||
* @param type - The event type to wait for
|
||||
* @param options - Optional event options including AbortSignal
|
||||
* @returns A promise that resolves with the event
|
||||
*/
|
||||
export function onEvent<K extends keyof HTMLElementEventMap>(
|
||||
target: HTMLElement,
|
||||
type: K,
|
||||
options?: OnEventOptions,
|
||||
): Promise<HTMLElementEventMap[K]>;
|
||||
|
||||
/**
|
||||
* Wait for an event to occur on a target.
|
||||
*
|
||||
* @param target - The event target (Window)
|
||||
* @param type - The event type to wait for
|
||||
* @param options - Optional event options including AbortSignal
|
||||
* @returns A promise that resolves with the event
|
||||
*/
|
||||
export function onEvent<K extends keyof WindowEventMap>(
|
||||
target: Window,
|
||||
type: K,
|
||||
options?: OnEventOptions,
|
||||
): Promise<WindowEventMap[K]>;
|
||||
|
||||
/**
|
||||
* Wait for an event to occur on a target.
|
||||
*
|
||||
* @param target - The event target (Document)
|
||||
* @param type - The event type to wait for
|
||||
* @param options - Optional event options including AbortSignal
|
||||
* @returns A promise that resolves with the event
|
||||
*/
|
||||
export function onEvent<K extends keyof DocumentEventMap>(
|
||||
target: Document,
|
||||
type: K,
|
||||
options?: OnEventOptions,
|
||||
): Promise<DocumentEventMap[K]>;
|
||||
|
||||
/**
|
||||
* Wait for an event to occur on a target.
|
||||
*
|
||||
* @param target - The event target
|
||||
* @param type - The event type to wait for
|
||||
* @param options - Optional event options including AbortSignal
|
||||
* @returns A promise that resolves with the event
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Wait for video to be seeked
|
||||
* const event = await onEvent(video, 'seeked');
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // With AbortSignal for cancellation
|
||||
* const controller = new AbortController();
|
||||
*
|
||||
* try {
|
||||
* const event = await onEvent(video, 'seeked', { signal: controller.signal });
|
||||
* } catch (e) {
|
||||
* if (e.name === 'AbortError') {
|
||||
* console.log('Cancelled waiting for event');
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // Cancel from elsewhere
|
||||
* controller.abort();
|
||||
* ```
|
||||
*/
|
||||
export function onEvent(target: EventTarget, type: string, options?: OnEventOptions): Promise<Event>;
|
||||
|
||||
export function onEvent(target: EventTarget, type: string, options?: OnEventOptions): Promise<Event> {
|
||||
|
||||
@@ -1,29 +1,12 @@
|
||||
import { supportsIdleCallback } from './supports';
|
||||
|
||||
/**
|
||||
* Request an idle callback and return a cleanup function to cancel it.
|
||||
*
|
||||
* Falls back to `setTimeout` with 1ms delay in environments that don't
|
||||
* support `requestIdleCallback` (e.g., Safari).
|
||||
*
|
||||
* @param callback - The callback to invoke when the browser is idle
|
||||
* @param options - Optional idle callback options (timeout, etc.)
|
||||
* @returns A cleanup function that cancels the idle callback request
|
||||
* Request an idle callback with cleanup. Falls back to setTimeout for Safari.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const cancel = idleCallback((deadline) => {
|
||||
* console.log('Time remaining:', deadline.timeRemaining());
|
||||
* });
|
||||
*
|
||||
* // Later, cancel if needed
|
||||
* cancel();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // With timeout option
|
||||
* const cancel = idleCallback(doWork, { timeout: 1000 });
|
||||
* cancel(); // Cancel if needed
|
||||
* ```
|
||||
*/
|
||||
export function idleCallback(callback: IdleRequestCallback, options?: IdleRequestOptions): () => void {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Add an event listener and return a cleanup function to remove it.
|
||||
*
|
||||
* @param target - The event target (HTMLMediaElement)
|
||||
* @param type - The event type
|
||||
* @param listener - The event listener
|
||||
* @param options - Optional event listener options
|
||||
* @returns A cleanup function that removes the event listener
|
||||
* @example
|
||||
* ```ts
|
||||
* const cleanup = listen(video, 'play', () => console.log('playing'));
|
||||
* cleanup(); // Remove listener
|
||||
* ```
|
||||
*/
|
||||
export function listen<K extends keyof HTMLMediaElementEventMap>(
|
||||
target: HTMLMediaElement,
|
||||
@@ -14,15 +14,6 @@ export function listen<K extends keyof HTMLMediaElementEventMap>(
|
||||
options?: AddEventListenerOptions,
|
||||
): () => void;
|
||||
|
||||
/**
|
||||
* Add an event listener and return a cleanup function to remove it.
|
||||
*
|
||||
* @param target - The event target (HTMLElement)
|
||||
* @param type - The event type
|
||||
* @param listener - The event listener
|
||||
* @param options - Optional event listener options
|
||||
* @returns A cleanup function that removes the event listener
|
||||
*/
|
||||
export function listen<K extends keyof HTMLElementEventMap>(
|
||||
target: HTMLElement,
|
||||
type: K,
|
||||
@@ -30,15 +21,6 @@ export function listen<K extends keyof HTMLElementEventMap>(
|
||||
options?: AddEventListenerOptions,
|
||||
): () => void;
|
||||
|
||||
/**
|
||||
* Add an event listener and return a cleanup function to remove it.
|
||||
*
|
||||
* @param target - The event target (Window)
|
||||
* @param type - The event type
|
||||
* @param listener - The event listener
|
||||
* @param options - Optional event listener options
|
||||
* @returns A cleanup function that removes the event listener
|
||||
*/
|
||||
export function listen<K extends keyof WindowEventMap>(
|
||||
target: Window,
|
||||
type: K,
|
||||
@@ -46,15 +28,6 @@ export function listen<K extends keyof WindowEventMap>(
|
||||
options?: AddEventListenerOptions,
|
||||
): () => void;
|
||||
|
||||
/**
|
||||
* Add an event listener and return a cleanup function to remove it.
|
||||
*
|
||||
* @param target - The event target (Document)
|
||||
* @param type - The event type
|
||||
* @param listener - The event listener
|
||||
* @param options - Optional event listener options
|
||||
* @returns A cleanup function that removes the event listener
|
||||
*/
|
||||
export function listen<K extends keyof DocumentEventMap>(
|
||||
target: Document,
|
||||
type: K,
|
||||
@@ -62,39 +35,6 @@ export function listen<K extends keyof DocumentEventMap>(
|
||||
options?: AddEventListenerOptions,
|
||||
): () => void;
|
||||
|
||||
/**
|
||||
* Add an event listener and return a cleanup function to remove it.
|
||||
*
|
||||
* @param target - The event target
|
||||
* @param type - The event type
|
||||
* @param listener - The event listener
|
||||
* @param options - Optional event listener options
|
||||
* @returns A cleanup function that removes the event listener
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const cleanup = listen(video, 'play', () => console.log('playing'));
|
||||
*
|
||||
* // Later, remove the listener
|
||||
* cleanup();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // With options
|
||||
* const cleanup = listen(video, 'play', handler, { once: true, passive: true });
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // With AbortSignal (native browser support)
|
||||
* const controller = new AbortController();
|
||||
* listen(video, 'play', handler, { signal: controller.signal });
|
||||
*
|
||||
* // Later, abort to remove the listener
|
||||
* controller.abort();
|
||||
* ```
|
||||
*/
|
||||
export function listen(
|
||||
target: EventTarget,
|
||||
type: string,
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
/**
|
||||
* Check if `requestIdleCallback` is supported.
|
||||
*
|
||||
* @returns `true` if `requestIdleCallback` is available
|
||||
*/
|
||||
export function supportsIdleCallback(): boolean {
|
||||
return typeof requestIdleCallback === 'function';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if `requestAnimationFrame` is supported.
|
||||
*
|
||||
* @returns `true` if `requestAnimationFrame` is available
|
||||
*/
|
||||
export function supportsAnimationFrame(): boolean {
|
||||
return typeof requestAnimationFrame === 'function';
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
/**
|
||||
* Converts a TimeRanges object to an array of [start, end] tuples.
|
||||
*
|
||||
* @param ranges - The TimeRanges object to serialize
|
||||
* @returns An array of [start, end] tuples
|
||||
*/
|
||||
/** Converts a TimeRanges object to an array of [start, end] tuples. */
|
||||
export function serializeTimeRanges(ranges: TimeRanges): Array<[number, number]> {
|
||||
const result: Array<[number, number]> = [];
|
||||
|
||||
|
||||
@@ -25,26 +25,15 @@ export type CleanupFn = () => void | Promise<void>;
|
||||
export class Disposer {
|
||||
#cleanups = new Set<CleanupFn>();
|
||||
|
||||
/**
|
||||
* Number of registered cleanup functions.
|
||||
*/
|
||||
get size(): number {
|
||||
return this.#cleanups.size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a cleanup function to the collection.
|
||||
*/
|
||||
add(cleanup: CleanupFn): void {
|
||||
this.#cleanups.add(cleanup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all cleanup functions synchronously.
|
||||
*
|
||||
* Note: If any cleanup functions return promises, they will not be awaited.
|
||||
* Use `disposeAsync()` if you have async cleanup functions.
|
||||
*/
|
||||
/** Run all cleanups sync. Use `disposeAsync()` for async cleanups. */
|
||||
dispose(): void {
|
||||
for (const cleanup of this.#cleanups) {
|
||||
cleanup();
|
||||
@@ -52,9 +41,6 @@ export class Disposer {
|
||||
this.#cleanups.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all cleanup functions, awaiting any promises.
|
||||
*/
|
||||
async disposeAsync(): Promise<void> {
|
||||
await Promise.all([...this.#cleanups].map(cleanup => cleanup()));
|
||||
this.#cleanups.clear();
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
/**
|
||||
* Wrap a function to catch and handle errors instead of throwing.
|
||||
*
|
||||
* @param fn - Function to wrap (can be undefined)
|
||||
* @param onError - Error handler (defaults to console.error)
|
||||
* @returns Wrapped function that never throws, or undefined if fn is undefined
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const safeFn = tryCatch(riskyFn, (e) => logger.error(e));
|
||||
|
||||
@@ -6,18 +6,10 @@ import { isObject } from '../predicate/predicate';
|
||||
export type Selector<State, Selected> = (state: State) => Selected;
|
||||
|
||||
/**
|
||||
* Extracts the state keys a selector depends on by running it once
|
||||
* and inspecting the result object's keys.
|
||||
*
|
||||
* Returns `null` if the selector returns a primitive or array
|
||||
* (keys cannot be determined).
|
||||
* Extract state keys a selector depends on. Returns null for primitives/arrays.
|
||||
*
|
||||
* @example
|
||||
* const selector = (s: State) => ({ volume: s.volume, muted: s.muted });
|
||||
* getSelectorKeys(selector, state); // ['volume', 'muted']
|
||||
*
|
||||
* const primitiveSelector = (s: State) => s.volume;
|
||||
* getSelectorKeys(primitiveSelector, state); // null
|
||||
* getSelectorKeys((s) => ({ volume: s.volume }), state); // ['volume']
|
||||
*/
|
||||
export function getSelectorKeys<State, Selected>(
|
||||
selector: Selector<State, Selected>,
|
||||
|
||||
@@ -19,8 +19,8 @@ describe('pick', () => {
|
||||
});
|
||||
|
||||
it('ignores non-existent keys', () => {
|
||||
const obj = { a: 1, b: 2 } as Record<string, number>;
|
||||
expect(pick(obj, ['a', 'nonexistent'] as (keyof typeof obj)[])).toEqual({ a: 1 });
|
||||
const obj = { a: 1, b: 2 };
|
||||
expect(pick(obj, ['a', 'nonexistent' as keyof typeof obj])).toEqual({ a: 1 });
|
||||
});
|
||||
|
||||
it('handles nested objects (shallow copy)', () => {
|
||||
|
||||
Reference in New Issue
Block a user