Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: lib/src/js_list.dart

Issue 615913004: Add @jsify annotation. Support automatically proxying Lists and Maps to Dart in Proxies. Support co… (Closed) Base URL: https://github.com/dart-lang/js-interop.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library js.js_list;
6
7 import 'dart:collection';
8 import 'dart:js';
9
10 import 'package:js/js.dart';
11
12 /**
13 * A [List] interface wrapper for [JsArray]s.
14 *
15 * Elements of this list are automatically converted to JavaScript with the
16 * [toJs] function when added, and converted to Dart with the [toDart] funtion
17 * when accessed.
18 */
19 class JsList<E> extends ListBase {
Siggi Cherem (dart-lang) 2014/10/07 20:41:41 ListBase<E>
alexandre.ardhuin 2014/10/08 09:00:49 +1 The commit in master does not contain this chan
20 JsArray _o;
21
22 JsList.fromJsObject(JsObject o) : _o = o;
23
24 @override
25 int get length => _o.length;
26
27 @override
28 void set length(int length) { _o.length = length; }
29
30 // TODO: add [E] as fallback type for toDart()
31 @override
32 E operator [](index) => toDart(_o[index]) as E;
33
34 @override
35 void operator []=(int index, E value) {
36 _o[index] = toJs(value);
37 }
38
39 @override
40 void add(E value) {
41 _o.add(toJs(value));
42 }
43
44 @override
45 void addAll(Iterable<E> iterable) {
46 _o.addAll(iterable.map(toJs));
47 }
48
49 @override
50 void sort([int compare(E a, E b)]) {
51 final sortedList = toList()..sort(compare);
52 setRange(0, sortedList.length, sortedList);
53 }
54
55 @override
56 void insert(int index, E element) {
57 _o.insert(index, toJs(element));
58 }
59
60 @override
61 E removeAt(int index) {
62 // TODO: add [E] as fallback type for toDart()
63 return toDart(_o.removeAt(index)) as E;
64 }
65
66 // TODO: add [E] as fallback type for toDart()
67 @override
68 E removeLast() => toDart(_o.removeLast()) as E;
69
70 @override
71 void setRange(int start, int end, List<E> iterable, [int startFrom = 0]) {
alexandre.ardhuin 2014/10/08 09:00:49 "iterable" is an List<E> here but it is a Iterable
72 _o.setRange(start, end, iterable.map(toJs), startFrom);
73 }
74
75 @override
76 void removeRange(int start, int end) {
77 _o.removeRange(start, end);
78 }
79 }
OLDNEW
« no previous file with comments | « lib/src/js_impl.dart ('k') | lib/src/js_object_map.dart » ('j') | lib/src/mirrors.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698