Skip to content

Commit 2335075

Browse files
committed
feat(facade): add ListWrapper.toJSON method
1 parent b3fc357 commit 2335075

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

modules/angular2/src/facade/collection.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
library facade.collection;
22

33
import 'dart:collection' show IterableBase, Iterator;
4+
import 'dart:convert' show JsonEncoder;
45
export 'dart:core' show Map, List, Set;
56
import 'dart:math' show max, min;
67

8+
var jsonEncoder = new JsonEncoder();
9+
710
class MapIterator extends Iterator<List> {
811
final Iterator _iterator;
912
final Map _map;
@@ -170,6 +173,10 @@ class ListWrapper {
170173
}
171174
}
172175

176+
static String toJSON(List l) {
177+
return jsonEncoder.convert(l);
178+
}
179+
173180
// JS splice, slice, fill functions can take start < 0 which indicates a position relative to
174181
// the end of the list
175182
static int _startOffset(List l, int start) {

modules/angular2/src/facade/collection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ export class ListWrapper {
238238
}
239239
}
240240
static toString<T>(l: List<T>): string { return l.toString(); }
241+
static toJSON<T>(l: List<T>): string { return JSON.stringify(l); }
242+
241243
}
242244

243245
export function isListLikeIterable(obj): boolean {

0 commit comments

Comments
 (0)