Skip to content

Commit

Permalink
fix(api): remove RecordViewTuple / cleanup NgFor
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Sep 15, 2015
1 parent 6db9f90 commit 61b6a47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 10 additions & 10 deletions modules/angular2/src/core/directives/ng_for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export class NgFor implements DoCheck {
changes.forEachMovedItem((movedRecord) =>
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));

var insertTuples = NgFor.bulkRemove(recordViewTuples, this._viewContainer);
var insertTuples = this._bulkRemove(recordViewTuples);

changes.forEachAddedItem((addedRecord) =>
insertTuples.push(new RecordViewTuple(addedRecord, null)));

NgFor.bulkInsert(insertTuples, this._viewContainer, this._templateRef);
this._bulkInsert(insertTuples);

for (var i = 0; i < insertTuples.length; i++) {
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
Expand All @@ -94,38 +94,38 @@ export class NgFor implements DoCheck {
view.setLocal('odd', (record.currentIndex % 2 == 1));
}

static bulkRemove(tuples: RecordViewTuple[], viewContainer: ViewContainerRef): RecordViewTuple[] {
private _bulkRemove(tuples: RecordViewTuple[]): RecordViewTuple[] {
tuples.sort((a, b) => a.record.previousIndex - b.record.previousIndex);
var movedTuples = [];
for (var i = tuples.length - 1; i >= 0; i--) {
var tuple = tuples[i];
// separate moved views from removed views.
if (isPresent(tuple.record.currentIndex)) {
tuple.view = viewContainer.detach(tuple.record.previousIndex);
tuple.view = this._viewContainer.detach(tuple.record.previousIndex);
movedTuples.push(tuple);
} else {
viewContainer.remove(tuple.record.previousIndex);
this._viewContainer.remove(tuple.record.previousIndex);
}
}
return movedTuples;
}

static bulkInsert(tuples: RecordViewTuple[], viewContainer: ViewContainerRef,
templateRef: TemplateRef): RecordViewTuple[] {
private _bulkInsert(tuples: RecordViewTuple[]): RecordViewTuple[] {
tuples.sort((a, b) => a.record.currentIndex - b.record.currentIndex);
for (var i = 0; i < tuples.length; i++) {
var tuple = tuples[i];
if (isPresent(tuple.view)) {
viewContainer.insert(tuple.view, tuple.record.currentIndex);
this._viewContainer.insert(tuple.view, tuple.record.currentIndex);
} else {
tuple.view = viewContainer.createEmbeddedView(templateRef, tuple.record.currentIndex);
tuple.view =
this._viewContainer.createEmbeddedView(this._templateRef, tuple.record.currentIndex);
}
}
return tuples;
}
}

export class RecordViewTuple {
class RecordViewTuple {
view: ViewRef;
record: any;
constructor(record, view) {
Expand Down
4 changes: 0 additions & 4 deletions modules/angular2/test/public_api_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,6 @@ const NG_API = [
'NgControlName.viewToModelUpdate',

'NgFor',
'NgFor.bulkInsert',
'NgFor.bulkRemove',
'NgFor.doCheck',
'NgFor.ngForOf',

Expand Down Expand Up @@ -770,8 +768,6 @@ const NG_API = [
'QueryMetadata.token',
'QueryMetadata.varBindings',

'RecordViewTuple', // TODO: private

'RenderDirectiveMetadata',
'RenderDirectiveMetadata.COMPONENT_TYPE',
'RenderDirectiveMetadata.DIRECTIVE_TYPE',
Expand Down

0 comments on commit 61b6a47

Please sign in to comment.