feat(query_list): delegate `toString` to `_results` array

Closes #3004
This commit is contained in:
gdi2290 2015-07-27 17:24:42 -07:00 committed by Rado Kirov
parent dfe0130753
commit 35a83b495a
3 changed files with 14 additions and 0 deletions

View File

@ -108,6 +108,9 @@ class QueryList<T> extends Object
int get length => _results.length;
T get first => _results.first;
T get last => _results.last;
String toString() {
return _results.toString();
}
List map(fn(T)) {
// Note: we need to return a list instead of iterable to match JS.

View File

@ -97,6 +97,8 @@ export class QueryList<T> {
removeCallback(callback: () => void): void { ListWrapper.remove(this._callbacks, callback); }
toString(): string { return this._results.toString(); }
get length(): number { return this._results.length; }
get first(): T { return ListWrapper.first(this._results); }
get last(): T { return ListWrapper.last(this._results); }

View File

@ -1,6 +1,7 @@
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib';
import {List, MapWrapper, ListWrapper, iterateListLike} from 'angular2/src/facade/collection';
import {StringWrapper} from 'angular2/src/facade/lang';
import {QueryList} from 'angular2/src/core/compiler/query_list';
@ -43,6 +44,14 @@ export function main() {
expect(queryList.map((x) => x)).toEqual(['one', 'two']);
});
it('should support toString', () => {
queryList.add('one');
queryList.add('two');
var listString = queryList.toString();
expect(StringWrapper.contains(listString, 'one')).toBeTruthy();
expect(StringWrapper.contains(listString, 'two')).toBeTruthy();
});
it('should support first and last', () => {
queryList.add('one');
queryList.add('two');