-
Notifications
You must be signed in to change notification settings - Fork 6
/
array.dart
69 lines (46 loc) · 1.61 KB
/
array.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
part of '../manual.dart';
@JS('Array')
@staticInterop
/// A [List] that proxies a JavaScript array.
class JsArray<E> {
/// Creates an empty JavaScript array.
external JsArray([E variadic1, E variadic2, E variadic3,
E variadic4, E variadic5]);
/// Creates a new JavaScript array and initializes it to the contents of
/// [other].
external JsArray.from(Iterable<E> other);
}
class JsArrayWrapper<E> extends ListBase<E> {
JsArrayWrapper(this._jsArray);
final JsArray<E> _jsArray;
@override
set length(int newLength) { _jsArray.length = newLength; }
@override
int get length => _jsArray.length;
@override
E operator [](int index) => _jsArray[index];
@override
void operator []=(int index, E value) { _jsArray[index] = value; }
}
extension AdvJsArray<E> on JsArray<E> {
List<E> toList() => JsArrayWrapper(this);
void forEach(void Function(E, int) fn) {
jsu.callMethod(this, 'forEach', [ allowInterop(fn)]);
}
E operator[](int key) => jsu.getProperty(this, key);
void operator[]=(int key, E value) =>
jsu.setProperty<E>(this, key, value);
external int get length;
external set length(int length);
// Methods overridden for better performance
external void add(E element);
external void addAll(Iterable<E> iterable);
external void insert(int index, E element);
external E removeAt(int index);
external E removeLast();
external void removeRange(int start, int end);
external String join(Object separator);
external void setRange(int start, int end, Iterable<E> iterable,
[int skipCount = 0]);
external void sort([int Function(E a, E b)? compare]);
}