@@ -49,39 +49,11 @@ function convertToInt(prop: number | string | symbol): number | null {
49
49
50
50
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
51
51
export 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 ; } ;
79
53
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 ;
83
56
84
- constructor ( arr : T [ ] = [ ] ) {
85
57
const clone = arr . slice ( ) ;
86
58
// eslint-disable-next-line @typescript-eslint/no-this-alias
87
59
const self = this ;
@@ -217,3 +189,13 @@ export interface TrackedArray<T = unknown> extends Array<T> {}
217
189
218
190
// Ensure instanceof works correctly
219
191
Object . 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