-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
item.ts
86 lines (73 loc) · 1.83 KB
/
item.ts
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
import { Routines } from './domRoutines';
import { Direction } from '../inputs/index';
import { Item as _Item, ItemAdapter } from '../interfaces/index';
export class Item<Data = unknown> implements _Item<Data> {
nodeId: string;
routines: Routines;
preSize: number; // estimated size
size: number; // real size
invisible: boolean;
toRemove: boolean;
toInsert: boolean;
removeDirection: Direction;
private container: ItemAdapter<Data>;
get $index(): number {
return this.container.$index;
}
set $index(value: number) {
this.container.$index = value;
}
get data(): Data {
return this.container.data;
}
set data(value: Data) {
this.container.data = value;
}
get element(): HTMLElement {
return this.container.element as HTMLElement;
}
set element(value: HTMLElement) {
this.container.element = value;
}
constructor($index: number, data: Data, routines: Routines) {
this.container = {
$index,
data
};
this.nodeId = String($index);
this.routines = routines;
this.invisible = true;
this.toRemove = false;
this.toInsert = false;
}
dispose(): void {
delete this.container.element;
}
setSize(preSize = 0): void {
this.preSize = preSize;
if (this.element) {
this.size = this.routines.getSize(this.element);
}
}
makeVisible(): void {
this.routines.makeElementVisible(this.element);
this.invisible = false;
}
hide(): void {
if (this.element) {
this.routines.hideElement(this.element);
}
}
scrollTo(argument?: boolean | ScrollIntoViewOptions): void {
if (this.element) {
this.routines.scrollTo(this.element, argument);
}
}
updateIndex(index: number): void {
this.$index = index;
this.nodeId = String(index);
}
get(): ItemAdapter<Data> {
return this.container;
}
}