/
contact-list.ts
106 lines (86 loc) · 2.16 KB
/
contact-list.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { computedFrom } from 'aurelia-framework';
declare const faker: any;
export class ContactList {
objectArray = [];
objectArray2 = [];
numberOfItems = 1000;
isSelected = false;
isVisible = true;
selectedMarkup = 'div';
viewStrategy: any;
$newArrayLength = 0;
setViewStrategy(strategy) {
this.viewStrategy = strategy;
}
toggle() {
this.isVisible = !this.isVisible;
}
click() {
console.log('click');
}
setIsSelected() {
this.isSelected = true;
}
createItem(index?: number) {
let name = faker.name.findName();
return {
firstLetter: name.charAt(0),
name: name,
color: faker.internet.color(),
phone: faker.phone.phoneNumber(),
country: faker.address.country()
};
}
activate() {
let name;
for (let i = 0; i < this.numberOfItems; ++i) {
name = faker.name.findName();
this.objectArray.push(this.createItem(i));
}
for (let i = 0; i < this.numberOfItems; ++i) {
name = faker.name.findName();
this.objectArray2.push(this.createItem());
}
}
@computedFrom('objectArray')
get contacts() {
return this.objectArray;
}
swap() {
this.objectArray = this.objectArray2;
}
addItems(count) {
console.log(`adding ${count} items...`);
for (let i = 0; i < count; ++i) {
this.objectArray.push(this.createItem(i));
}
console.log(`finsihed adding ${count} items`);
this.numberOfItems = this.objectArray.length;
}
addItem2() {
let item = this.createItem();
this.objectArray.splice(1, 0, item);
}
addItemFirst(count = 10) {
for (let i = 0; i < count; ++i) {
this.objectArray.unshift(this.createItem());
}
}
removeItems(count) {
this.objectArray.splice(0, count);
}
unshift5() {
this.objectArray.unshift(this.createItem(), this.createItem(), this.createItem(), this.createItem(), this.createItem());
}
addItemLast(count = 10) {
while (count-- > 0) {
this.objectArray.push(this.createItem());
}
}
removeLast() {
this.objectArray.pop();
}
newRandomArray(count = 1000) {
this.objectArray = Array.from({ length: count }, () => this.createItem());
}
}