feat(core): Add `QueryList#forEach`

This commit is contained in:
laco0416 2016-01-08 15:34:25 +09:00 committed by Matias Niemela
parent c1a0af514f
commit b634a25ae0
2 changed files with 12 additions and 0 deletions

View File

@ -51,6 +51,11 @@ export class QueryList<T> {
*/
reduce<U>(fn: (acc: U, item: T) => U, init: U): U { return this._results.reduce(fn, init); }
/**
* executes function for each element in a query.
*/
forEach(fn: (item: T) => void): void { this._results.forEach(fn); }
/**
* converts QueryList into an array
*/

View File

@ -50,6 +50,13 @@ export function main() {
expect(queryList.map((x) => x)).toEqual(['one', 'two']);
});
it('should support forEach', () => {
queryList.reset(['one', 'two']);
let join = '';
queryList.forEach((x) => join = join + x);
expect(join).toEqual('onetwo');
});
if (!IS_DART) {
it('should support filter', () => {
queryList.reset(['one', 'two']);