diff --git a/modules/angular2/change_detection.js b/modules/angular2/change_detection.js index c8ac4e7093..3583c76f1d 100644 --- a/modules/angular2/change_detection.js +++ b/modules/angular2/change_detection.js @@ -18,7 +18,7 @@ export * from './src/change_detection/pipes/pipe'; import {ProtoChangeDetector, DynamicProtoChangeDetector, JitProtoChangeDetector} from './src/change_detection/proto_change_detector'; import {PipeRegistry} from './src/change_detection/pipes/pipe_registry'; -import {ArrayChangesFactory} from './src/change_detection/pipes/array_changes'; +import {IterableChangesFactory} from './src/change_detection/pipes/iterable_changes'; import {KeyValueChangesFactory} from './src/change_detection/pipes/keyvalue_changes'; import {NullPipeFactory} from './src/change_detection/pipes/null_pipe'; @@ -31,7 +31,7 @@ export class ChangeDetection { export var defaultPipes = { "iterableDiff" : [ - new ArrayChangesFactory(), + new IterableChangesFactory(), new NullPipeFactory() ], "keyValDiff" : [ diff --git a/modules/angular2/directives.js b/modules/angular2/directives.js index 6a1b817ab5..789fbc053f 100644 --- a/modules/angular2/directives.js +++ b/modules/angular2/directives.js @@ -1,4 +1,4 @@ -export * from './src/directives/foreach'; +export * from './src/directives/for'; export * from './src/directives/if'; export * from './src/directives/non_bindable'; export * from './src/directives/switch'; diff --git a/modules/angular2/src/change_detection/pipes/array_changes.js b/modules/angular2/src/change_detection/pipes/iterable_changes.js similarity index 98% rename from modules/angular2/src/change_detection/pipes/array_changes.js rename to modules/angular2/src/change_detection/pipes/iterable_changes.js index 10fa537553..bf5e3dee6e 100644 --- a/modules/angular2/src/change_detection/pipes/array_changes.js +++ b/modules/angular2/src/change_detection/pipes/iterable_changes.js @@ -16,17 +16,17 @@ import { import {NO_CHANGE, Pipe} from './pipe'; -export class ArrayChangesFactory { +export class IterableChangesFactory { supports(obj):boolean { - return ArrayChanges.supportsObj(obj); + return IterableChanges.supportsObj(obj); } create():Pipe { - return new ArrayChanges(); + return new IterableChanges(); } } -export class ArrayChanges extends Pipe { +export class IterableChanges extends Pipe { _collection; _length:int; _linkedRecords:_DuplicateMap; @@ -66,7 +66,7 @@ export class ArrayChanges extends Pipe { } supports(obj):boolean { - return ArrayChanges.supportsObj(obj); + return IterableChanges.supportsObj(obj); } get collection() { diff --git a/modules/angular2/src/directives/foreach.js b/modules/angular2/src/directives/for.js similarity index 91% rename from modules/angular2/src/directives/foreach.js rename to modules/angular2/src/directives/for.js index 44ca00b048..01fd4428bf 100644 --- a/modules/angular2/src/directives/foreach.js +++ b/modules/angular2/src/directives/for.js @@ -5,12 +5,12 @@ import {isPresent, isBlank} from 'angular2/src/facade/lang'; import {ListWrapper} from 'angular2/src/facade/collection'; @Viewport({ - selector: '[foreach][in]', + selector: '[for][of]', bind: { - 'iterableChanges': 'in | iterableDiff' + 'iterableChanges': 'of | iterableDiff' } }) -export class Foreach { +export class For { viewContainer: ViewContainer; constructor(viewContainer:ViewContainer) { super(); @@ -34,13 +34,13 @@ export class Foreach { (movedRecord) => ListWrapper.push(recordViewTuples, new RecordViewTuple(movedRecord, null)) ); - var insertTuples = Foreach.bulkRemove(recordViewTuples, this.viewContainer); + var insertTuples = For.bulkRemove(recordViewTuples, this.viewContainer); changes.forEachAddedItem( (addedRecord) => ListWrapper.push(insertTuples, new RecordViewTuple(addedRecord, null)) ); - Foreach.bulkInsert(insertTuples, this.viewContainer); + For.bulkInsert(insertTuples, this.viewContainer); for (var i = 0; i < insertTuples.length; i++) { this.perViewChange(insertTuples[i].view, insertTuples[i].record); diff --git a/modules/angular2/test/change_detection/array_changes_spec.js b/modules/angular2/test/change_detection/iterable_changes_spec.js similarity index 77% rename from modules/angular2/test/change_detection/array_changes_spec.js rename to modules/angular2/test/change_detection/iterable_changes_spec.js index aeea7169a1..d5e8da0f9f 100644 --- a/modules/angular2/test/change_detection/array_changes_spec.js +++ b/modules/angular2/test/change_detection/iterable_changes_spec.js @@ -1,11 +1,11 @@ import {describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib'; -import {ArrayChanges} from 'angular2/src/change_detection/pipes/array_changes'; +import {IterableChanges} from 'angular2/src/change_detection/pipes/iterable_changes'; import {NumberWrapper} from 'angular2/src/facade/lang'; import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; import {TestIterable} from './iterable'; -import {arrayChangesAsString} from './util'; +import {iterableChangesAsString} from './util'; // todo(vicb): UnmodifiableListView / frozen object when implemented export function main() { @@ -15,7 +15,7 @@ export function main() { var l; beforeEach(() => { - changes = new ArrayChanges(); + changes = new IterableChanges(); }); afterEach(() => { @@ -23,30 +23,30 @@ export function main() { }); it('should support list and iterables', () => { - expect(ArrayChanges.supportsObj([])).toBeTruthy(); - expect(ArrayChanges.supportsObj(new TestIterable())).toBeTruthy(); - expect(ArrayChanges.supportsObj(MapWrapper.create())).toBeFalsy(); - expect(ArrayChanges.supportsObj(null)).toBeFalsy(); + expect(IterableChanges.supportsObj([])).toBeTruthy(); + expect(IterableChanges.supportsObj(new TestIterable())).toBeTruthy(); + expect(IterableChanges.supportsObj(MapWrapper.create())).toBeFalsy(); + expect(IterableChanges.supportsObj(null)).toBeFalsy(); }); it('should support iterables', () => { l = new TestIterable(); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: [] })); l.list = [1]; changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['1[null->0]'], additions: ['1[null->0]'] })); l.list = [2, 1]; changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['2[null->0]', '1[0->1]'], previous: ['1[0->1]'], additions: ['2[null->0]'], @@ -57,20 +57,20 @@ export function main() { it('should detect additions', () => { l = []; changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: [] })); ListWrapper.push(l, 'a'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a[null->0]'], additions: ['a[null->0]'] })); ListWrapper.push(l, 'b'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'b[null->1]'], previous: ['a'], additions: ['b[null->1]'] @@ -83,7 +83,7 @@ export function main() { l = [1, 0]; changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['1[null->0]', '0[0->1]'], previous: ['0[0->1]'], additions: ['1[null->0]'], @@ -92,7 +92,7 @@ export function main() { l = [2, 1, 0]; changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['2[null->0]', '1[0->1]', '0[1->2]'], previous: ['1[0->1]', '0[1->2]'], additions: ['2[null->0]'], @@ -108,7 +108,7 @@ export function main() { ListWrapper.push(l, 2); ListWrapper.push(l, 1); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['2[1->0]', '1[0->1]'], previous: ['1[0->1]', '2[1->0]'], moves: ['2[1->0]', '1[0->1]'] @@ -122,7 +122,7 @@ export function main() { ListWrapper.removeAt(l, 1); ListWrapper.insert(l, 0, 'b'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['b[1->0]', 'a[0->1]', 'c'], previous: ['a[0->1]', 'b[1->0]', 'c'], moves: ['b[1->0]', 'a[0->1]'] @@ -131,7 +131,7 @@ export function main() { ListWrapper.removeAt(l, 1); ListWrapper.push(l, 'a'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['b', 'c[2->1]', 'a[1->2]'], previous: ['b', 'a[1->2]', 'c[2->1]'], moves: ['c[2->1]', 'a[1->2]'] @@ -144,14 +144,14 @@ export function main() { ListWrapper.push(l, 'a'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a[null->0]'], additions: ['a[null->0]'] })); ListWrapper.push(l, 'b'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'b[null->1]'], previous: ['a'], additions: ['b[null->1]'] @@ -160,7 +160,7 @@ export function main() { ListWrapper.push(l, 'c'); ListWrapper.push(l, 'd'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'b', 'c[null->2]', 'd[null->3]'], previous: ['a', 'b'], additions: ['c[null->2]', 'd[null->3]'] @@ -168,7 +168,7 @@ export function main() { ListWrapper.removeAt(l, 2); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'b', 'd[3->2]'], previous: ['a', 'b', 'c[2->null]', 'd[3->2]'], moves: ['d[3->2]'], @@ -181,7 +181,7 @@ export function main() { ListWrapper.push(l, 'b'); ListWrapper.push(l, 'a'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['d[2->0]', 'c[null->1]', 'b[1->2]', 'a[0->3]'], previous: ['a[0->3]', 'b[1->2]', 'd[2->0]'], additions: ['c[null->1]'], @@ -197,7 +197,7 @@ export function main() { var oo = 'oo'; ListWrapper.set(l, 1, b + oo); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'boo'], previous: ['a', 'boo'] })); @@ -207,7 +207,7 @@ export function main() { l = [NumberWrapper.NaN]; changes.check(l); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: [NumberWrapper.NaN], previous: [NumberWrapper.NaN] })); @@ -219,7 +219,7 @@ export function main() { ListWrapper.insert(l, 0, 'foo'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['foo[null->0]', 'NaN[0->1]', 'NaN[1->2]'], previous: ['NaN[0->1]', 'NaN[1->2]'], additions: ['foo[null->0]'], @@ -233,7 +233,7 @@ export function main() { ListWrapper.removeAt(l, 1); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'c[2->1]'], previous: ['a', 'b[1->null]', 'c[2->1]'], moves: ['c[2->1]'], @@ -242,7 +242,7 @@ export function main() { ListWrapper.insert(l, 1, 'b'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'b[null->1]', 'c[1->2]'], previous: ['a', 'c[1->2]'], additions: ['b[null->1]'], @@ -256,7 +256,7 @@ export function main() { ListWrapper.removeAt(l, 0); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['a', 'a', 'b[3->2]', 'b[4->3]'], previous: ['a', 'a', 'a[2->null]', 'b[3->2]', 'b[4->3]'], moves: ['b[3->2]', 'b[4->3]'], @@ -270,7 +270,7 @@ export function main() { ListWrapper.insert(l, 0, 'b'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['b[2->0]', 'a[0->1]', 'a[1->2]', 'b', 'b[null->4]'], previous: ['a[0->1]', 'a[1->2]', 'b[2->0]', 'b'], additions: ['b[null->4]'], @@ -287,7 +287,7 @@ export function main() { ListWrapper.push(l, 'a'); ListWrapper.push(l, 'c'); changes.check(l); - expect(changes.toString()).toEqual(arrayChangesAsString({ + expect(changes.toString()).toEqual(iterableChangesAsString({ collection: ['b[1->0]', 'a[0->1]', 'c'], previous: ['a[0->1]', 'b[1->0]', 'c'], moves: ['b[1->0]', 'a[0->1]'] diff --git a/modules/angular2/test/change_detection/util.js b/modules/angular2/test/change_detection/util.js index 45e5b02ee7..9e59178b46 100644 --- a/modules/angular2/test/change_detection/util.js +++ b/modules/angular2/test/change_detection/util.js @@ -1,6 +1,6 @@ import {isBlank} from 'angular2/src/facade/lang'; -export function arrayChangesAsString({collection, previous, additions, moves, removals}) { +export function iterableChangesAsString({collection, previous, additions, moves, removals}) { if (isBlank(collection)) collection = []; if (isBlank(previous)) previous = []; if (isBlank(additions)) additions = []; diff --git a/modules/angular2/test/directives/foreach_spec.js b/modules/angular2/test/directives/for_spec.js similarity index 88% rename from modules/angular2/test/directives/foreach_spec.js rename to modules/angular2/test/directives/for_spec.js index 6657814c9d..61b06b116d 100644 --- a/modules/angular2/test/directives/foreach_spec.js +++ b/modules/angular2/test/directives/for_spec.js @@ -25,12 +25,12 @@ import {Decorator, Component, Viewport} from 'angular2/src/core/annotations/anno import {MockTemplateResolver} from 'angular2/src/mock/template_resolver_mock'; -import {Foreach} from 'angular2/src/directives/foreach'; +import {For} from 'angular2/src/directives/for'; import {bind} from 'angular2/di'; export function main() { - describe('foreach', () => { + describe('for', () => { var view, cd, compiler, component, tplResolver; beforeEachBindings(() => [ @@ -52,13 +52,13 @@ export function main() { function compileWithTemplate(html) { var template = new Template({ inline: html, - directives: [Foreach] + directives: [For] }); tplResolver.setTemplate(TestComponent, template); return compiler.compile(TestComponent); } - var TEMPLATE = '
{{item.toString()}};
'; + var TEMPLATE = '
{{item.toString()}};
'; it('should reflect initial elements', inject([AsyncTestCompleter], (async) => { compileWithTemplate(TEMPLATE).then((pv) => { @@ -124,8 +124,8 @@ export function main() { }); })); - it('should iterate over an array of objects', () => { - compileWithTemplate('').then((pv) => { + it('should iterate over an array of objects', inject([AsyncTestCompleter], (async) => { + compileWithTemplate('').then((pv) => { createView(pv); // INIT @@ -145,11 +145,12 @@ export function main() { cd.detectChanges(); expect(DOM.getText(view.nodes[0])).toEqual('shyam;'); + async.done(); }); - }); + })); it('should gracefully handle nulls', inject([AsyncTestCompleter], (async) => { - compileWithTemplate('').then((pv) => { + compileWithTemplate('').then((pv) => { createView(pv); cd.detectChanges(); expect(DOM.getText(view.nodes[0])).toEqual(''); @@ -199,10 +200,13 @@ export function main() { it('should repeat over nested arrays', inject([AsyncTestCompleter], (async) => { compileWithTemplate( - '
' + - '
' + - '{{subitem}}-{{item.length}};' + - '
|
' + '
'+ + '
' + + '
' + + '{{subitem}}-{{item.length}};' + + '
|'+ + '
'+ + '
' ).then((pv) => { createView(pv); component.items = [['a', 'b'], ['c']]; @@ -216,7 +220,7 @@ export function main() { it('should display indices correctly', inject([AsyncTestCompleter], (async) => { var INDEX_TEMPLATE = - '
{{i.toString()}}
'; + '
{{i.toString()}}
'; compileWithTemplate(INDEX_TEMPLATE).then((pv) => { createView(pv); component.items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; diff --git a/modules/benchmarks/src/naive_infinite_scroll/app.js b/modules/benchmarks/src/naive_infinite_scroll/app.js index da0511c4df..2dc189c0c6 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/app.js +++ b/modules/benchmarks/src/naive_infinite_scroll/app.js @@ -6,7 +6,7 @@ import {bootstrap, Component, Viewport, Template, ViewContainer, Compiler} import {PromiseWrapper} from 'angular2/src/facade/async'; import {ListWrapper} from 'angular2/src/facade/collection'; import {ScrollAreaComponent} from './scroll_area'; -import {If, Foreach} from 'angular2/directives'; +import {If, For} from 'angular2/directives'; import {DOM} from 'angular2/src/dom/dom_adapter'; import {document} from 'angular2/src/facade/browser'; @@ -85,7 +85,7 @@ export function setupReflectorForApp() { 'annotations': [ new Component({selector: 'scroll-app'}), new Template({ - directives: [ScrollAreaComponent, If, Foreach], + directives: [ScrollAreaComponent, If, For], inline: `
@@ -93,7 +93,7 @@ export function setupReflectorForApp() {

Following tables are only here to add weight to the UI:

- +
` })] diff --git a/modules/benchmarks/src/naive_infinite_scroll/cells.js b/modules/benchmarks/src/naive_infinite_scroll/cells.js index 2a1c391fd6..2f2e9444cc 100644 --- a/modules/benchmarks/src/naive_infinite_scroll/cells.js +++ b/modules/benchmarks/src/naive_infinite_scroll/cells.js @@ -7,7 +7,7 @@ import {PromiseWrapper} from 'angular2/src/facade/async'; import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; import {Company, Opportunity, Offering, Account, CustomDate, STATUS_LIST} from './common'; -import {Foreach} from 'angular2/directives'; +import {For} from 'angular2/directives'; export class HasStyle { style:Map; @@ -163,10 +163,10 @@ export function setupReflectorForCells() { } }), new Template({ - directives: [Foreach], + directives: [For], inline: `
-