This repository was archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathng_repeat.js
61 lines (58 loc) · 1.6 KB
/
ng_repeat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import {TemplateDirective} from '../annotations';
import {Inject} from 'di';
import {BoundViewFactory, InitAttrs} from '../view_factory';
import {ViewPort} from '../view';
@TemplateDirective({
selector: '[ng-repeat]',
bind: {
'ngRepeat': 'ngRepeat'
},
observe: {
'ngRepeat[]': 'ngRepeatChanged'
}
})
export class NgRepeat {
@Inject(BoundViewFactory, ViewPort, 'executionContext')
constructor(viewFactory, viewPort, parentExecutionContext) {
this.viewFactory = viewFactory;
this.parentExecutionContext = parentExecutionContext;
this.viewPort = viewPort;
this.views = [];
this.ngRepeat = null;
}
ngRepeatChanged(changeRecord) {
var self = this;
if (changeRecord && changeRecord.additionsHead && !changeRecord.movesHead && !changeRecord.removalsHead) {
var entry = changeRecord.additionsHead;
while (entry) {
addRow(entry.item);
entry = entry.nextAddedRec;
}
return;
}
var rows;
if (changeRecord) {
rows = changeRecord.iterable;
} else {
rows = [];
}
// TODO: Update the views incrementally!
this.views.forEach((view) => {
view.remove();
});
this.views = [];
rows.forEach(addRow);
function addRow(row) {
var context = Object.create(self.parentExecutionContext);
context.row = row;
var view = self.viewFactory.createView({executionContext: context});
var lastView = self.views[self.views.length-1];
if (lastView) {
view.insertAfterView(lastView);
} else {
view.appendTo(self.viewPort);
}
self.views.push(view);
}
}
}