@@ -49,39 +49,11 @@ function convertToInt(prop: number | string | symbol): number | null {
4949
5050// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
5151export class TrackedArray < T = unknown > {
52- /**
53- * Creates an array from an iterable object.
54- * @param iterable An iterable object to convert to an array.
55- */
56- static from < T > ( iterable : Iterable < T > | ArrayLike < T > ) : TrackedArray < T > ;
57-
58- /**
59- * Creates an array from an iterable object.
60- * @param iterable An iterable object to convert to an array.
61- * @param mapfn A mapping function to call on every element of the array.
62- * @param thisArg Value of 'this' used to invoke the mapfn.
63- */
64- static from < T , U > (
65- iterable : Iterable < T > | ArrayLike < T > ,
66- mapfn : ( v : T , k : number ) => U ,
67- thisArg ?: unknown
68- ) : TrackedArray < U > ;
69-
70- static from < T , U > (
71- iterable : Iterable < T > | ArrayLike < T > ,
72- mapfn ?: ( v : T , k : number ) => U ,
73- thisArg ?: unknown
74- ) : TrackedArray < T > | TrackedArray < U > {
75- return mapfn
76- ? new TrackedArray ( Array . from ( iterable , mapfn , thisArg ) )
77- : new TrackedArray ( Array . from ( iterable ) ) ;
78- }
52+ #options: { equals : ( a : T , b : T ) => boolean ; description : string | undefined ; } ;
7953
80- static of < T > ( ...arr : T [ ] ) : TrackedArray < T > {
81- return new TrackedArray ( arr ) ;
82- }
54+ constructor ( arr : T [ ] , options : { equals : ( a : T , b : T ) => boolean ; description : string | undefined } ) {
55+ this . #options = options ;
8356
84- constructor ( arr : T [ ] = [ ] ) {
8557 const clone = arr . slice ( ) ;
8658 // eslint-disable-next-line @typescript-eslint/no-this-alias
8759 const self = this ;
@@ -217,3 +189,13 @@ export interface TrackedArray<T = unknown> extends Array<T> {}
217189
218190// Ensure instanceof works correctly
219191Object . setPrototypeOf ( TrackedArray . prototype , Array . prototype ) ;
192+
193+ export function trackedArray < T = unknown > (
194+ data ?: T [ ] ,
195+ options ?: { equals ?: ( a : T , b : T ) => boolean ; description ?: string }
196+ ) : TrackedArray < T > {
197+ return new TrackedArray ( data ?? [ ] , {
198+ equals : options ?. equals ?? Object . is ,
199+ description : options ?. description ,
200+ } ) ;
201+ }
0 commit comments