-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtable-rows.js
100 lines (80 loc) · 2.19 KB
/
table-rows.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import Ember from 'ember';
import layout from '../templates/components/table-rows';
const {
Component,
run,
get
} = Ember;
export default Component.extend({
layout,
tagName: 'tbody',
content: null,
hideOffscreenContent: true,
topRowIndex: 0,
bottomRowIndex: 0,
rowHeight: 37,
itemClassNames: '',
_hasInitialized: false,
_children: null,
register(child) {
this.get('_children').addObject(child);
if (this._hasInitialized) {
this.scheduleChildrenUpdate();
}
},
unregister(child) {
let children = this.get('_children');
if (children) {
children.removeObject(child);
if (this._hasInitialized && !this.get('isDestroying') && !this.get('isDestroyed')) {
this.scheduleChildrenUpdate();
}
}
},
scheduleChildrenUpdate(args) {
if (this._hasInitialized) {
run.scheduleOnce('actions', this, this._updateChildren, args);
}
},
_updateChildren() {
let children = this.get('_children').sortBy('index');
if (!get(children, 'length')) {
return;
}
let { topRowIndex, bottomRowIndex } = this.get('table').getVisibleRowIndexes();
let childrenToHide = children.slice(0, topRowIndex);
childrenToHide = childrenToHide.concat(children.slice(bottomRowIndex));
let childrenToShow = children.slice(topRowIndex, bottomRowIndex);
childrenToHide.forEach((child) => child.hide());
childrenToShow.forEach((child) => child.show());
},
didReceiveAttrs() {
// this.scheduleChildrenUpdate();
},
didInsertElement() {
this._super(...arguments);
run.next(() => {
this._hasInitialized = true;
this.scheduleChildrenUpdate();
});
},
willDestroy() {
this._super(...arguments);
this._destroyCollection();
},
willDestroyElement() {
this._super(...arguments);
this._destroyCollection();
},
_destroyCollection() {
// TODO: reimplement with _content in order to fully clear it out on destroy?
// this.set('content', null);
this.set('_children', null);
this.get('table').unregisterRowManager(this);
},
init() {
this._super(...arguments);
this.set('_children', Ember.A());
this.get('table').registerRowManager(this);
}
});