fix(api): remove RecordViewTuple / cleanup NgFor
This commit is contained in:
parent
6db9f9013d
commit
61b6a475a6
|
@ -71,12 +71,12 @@ export class NgFor implements DoCheck {
|
||||||
changes.forEachMovedItem((movedRecord) =>
|
changes.forEachMovedItem((movedRecord) =>
|
||||||
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));
|
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));
|
||||||
|
|
||||||
var insertTuples = NgFor.bulkRemove(recordViewTuples, this._viewContainer);
|
var insertTuples = this._bulkRemove(recordViewTuples);
|
||||||
|
|
||||||
changes.forEachAddedItem((addedRecord) =>
|
changes.forEachAddedItem((addedRecord) =>
|
||||||
insertTuples.push(new RecordViewTuple(addedRecord, null)));
|
insertTuples.push(new RecordViewTuple(addedRecord, null)));
|
||||||
|
|
||||||
NgFor.bulkInsert(insertTuples, this._viewContainer, this._templateRef);
|
this._bulkInsert(insertTuples);
|
||||||
|
|
||||||
for (var i = 0; i < insertTuples.length; i++) {
|
for (var i = 0; i < insertTuples.length; i++) {
|
||||||
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
|
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
|
||||||
|
@ -94,38 +94,38 @@ export class NgFor implements DoCheck {
|
||||||
view.setLocal('odd', (record.currentIndex % 2 == 1));
|
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);
|
tuples.sort((a, b) => a.record.previousIndex - b.record.previousIndex);
|
||||||
var movedTuples = [];
|
var movedTuples = [];
|
||||||
for (var i = tuples.length - 1; i >= 0; i--) {
|
for (var i = tuples.length - 1; i >= 0; i--) {
|
||||||
var tuple = tuples[i];
|
var tuple = tuples[i];
|
||||||
// separate moved views from removed views.
|
// separate moved views from removed views.
|
||||||
if (isPresent(tuple.record.currentIndex)) {
|
if (isPresent(tuple.record.currentIndex)) {
|
||||||
tuple.view = viewContainer.detach(tuple.record.previousIndex);
|
tuple.view = this._viewContainer.detach(tuple.record.previousIndex);
|
||||||
movedTuples.push(tuple);
|
movedTuples.push(tuple);
|
||||||
} else {
|
} else {
|
||||||
viewContainer.remove(tuple.record.previousIndex);
|
this._viewContainer.remove(tuple.record.previousIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return movedTuples;
|
return movedTuples;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bulkInsert(tuples: RecordViewTuple[], viewContainer: ViewContainerRef,
|
private _bulkInsert(tuples: RecordViewTuple[]): RecordViewTuple[] {
|
||||||
templateRef: TemplateRef): RecordViewTuple[] {
|
|
||||||
tuples.sort((a, b) => a.record.currentIndex - b.record.currentIndex);
|
tuples.sort((a, b) => a.record.currentIndex - b.record.currentIndex);
|
||||||
for (var i = 0; i < tuples.length; i++) {
|
for (var i = 0; i < tuples.length; i++) {
|
||||||
var tuple = tuples[i];
|
var tuple = tuples[i];
|
||||||
if (isPresent(tuple.view)) {
|
if (isPresent(tuple.view)) {
|
||||||
viewContainer.insert(tuple.view, tuple.record.currentIndex);
|
this._viewContainer.insert(tuple.view, tuple.record.currentIndex);
|
||||||
} else {
|
} else {
|
||||||
tuple.view = viewContainer.createEmbeddedView(templateRef, tuple.record.currentIndex);
|
tuple.view =
|
||||||
|
this._viewContainer.createEmbeddedView(this._templateRef, tuple.record.currentIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tuples;
|
return tuples;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RecordViewTuple {
|
class RecordViewTuple {
|
||||||
view: ViewRef;
|
view: ViewRef;
|
||||||
record: any;
|
record: any;
|
||||||
constructor(record, view) {
|
constructor(record, view) {
|
||||||
|
|
|
@ -557,8 +557,6 @@ const NG_API = [
|
||||||
'NgControlName.viewToModelUpdate',
|
'NgControlName.viewToModelUpdate',
|
||||||
|
|
||||||
'NgFor',
|
'NgFor',
|
||||||
'NgFor.bulkInsert',
|
|
||||||
'NgFor.bulkRemove',
|
|
||||||
'NgFor.doCheck',
|
'NgFor.doCheck',
|
||||||
'NgFor.ngForOf',
|
'NgFor.ngForOf',
|
||||||
|
|
||||||
|
@ -770,8 +768,6 @@ const NG_API = [
|
||||||
'QueryMetadata.token',
|
'QueryMetadata.token',
|
||||||
'QueryMetadata.varBindings',
|
'QueryMetadata.varBindings',
|
||||||
|
|
||||||
'RecordViewTuple', // TODO: private
|
|
||||||
|
|
||||||
'RenderDirectiveMetadata',
|
'RenderDirectiveMetadata',
|
||||||
'RenderDirectiveMetadata.COMPONENT_TYPE',
|
'RenderDirectiveMetadata.COMPONENT_TYPE',
|
||||||
'RenderDirectiveMetadata.DIRECTIVE_TYPE',
|
'RenderDirectiveMetadata.DIRECTIVE_TYPE',
|
||||||
|
|
Loading…
Reference in New Issue