valtio
Version:
🧙 Valtio makes proxy-state simple for React and Vanilla
47 lines (46 loc) • 1.58 kB
text/typescript
type RSetLike<T> = {
has(value: T): boolean;
};
type InternalProxySet<T> = Set<T> & {
data: T[];
toJSON: () => object;
index: number;
epoch: number;
intersection<U>(other: RSetLike<U>): Set<T & U>;
intersection(other: Set<T>): Set<T>;
union<U>(other: RSetLike<U>): Set<T | U>;
union(other: Set<T>): Set<T>;
difference<U>(other: RSetLike<U>): Set<T>;
difference(other: Set<T>): Set<T>;
symmetricDifference<U>(other: RSetLike<U>): Set<T | U>;
symmetricDifference(other: Set<T>): Set<T>;
isSubsetOf(other: RSetLike<T>): boolean;
isSupersetOf(other: RSetLike<T>): boolean;
isDisjointFrom(other: RSetLike<T>): boolean;
};
/**
* Determines if an object is a proxy Set created with proxySet
*/
export declare const isProxySet: (obj: object) => boolean;
/**
* Creates a reactive Set that integrates with Valtio's proxy system
*
* This utility creates a Set-like object that works with Valtio's reactivity system,
* allowing you to track changes to the Set in the same way as regular proxy objects.
* The API extends the standard JavaScript Set with additional set operations like
* union, intersection, difference, etc.
*
* @example
* import { proxySet } from 'valtio/utils'
* const state = proxySet([1,2,3])
*
* // can be used inside a proxy as well
* const state = proxy({
* count: 1,
* set: proxySet()
* })
*/
export declare function proxySet<T>(initialValues?: Iterable<T> | null): InternalProxySet<T> & {
$$valtioSnapshot: Omit<InternalProxySet<T>, "set" | "delete" | "clear">;
};
export {};