This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
/
app.component.ts
87 lines (79 loc) · 2.28 KB
/
app.component.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
import { Component } from '@angular/core';
import {
AngularFireOfflineDatabase,
AfoListObservable,
AfoObjectObservable
} from 'angularfire2-offline/database';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
groceriesList: AfoListObservable<any[]>;
groceriesObject: AfoObjectObservable<any>;
processing = false;
max = 49;
currentId = 1;
totalTime: number;
totalToAdd = 50;
constructor(private afoDatabase: AngularFireOfflineDatabase) {
this.groceriesList = this.afoDatabase.list('groceries');
this.groceriesObject = this.afoDatabase.object('groceries');
}
removeAll() {
const startTime = performance.now();
this.processing = true;
this.groceriesList.remove()
.then(() => {
this.processing = false;
this.updateTime(startTime);
});
}
usingPush() {
const startTime = performance.now();
this.processing = true;
const updates = [];
const max = this.max + this.currentId;
for (this.currentId; this.currentId <= max; ++this.currentId) {
updates.push(this.groceriesList.push({text: 'Milk'}));
}
Promise.all(updates)
.then(() => {
this.processing = false;
this.updateTime(startTime);
});
}
usingUpdate() {
const startTime = performance.now();
this.processing = true;
const updates = [];
const max = this.max + this.currentId;
for (this.currentId; this.currentId <= max; ++this.currentId) {
updates.push(this.groceriesList.update(`${this.currentId}`, {text: 'Milk'}));
}
Promise.all(updates)
.then(() => {
this.processing = false;
this.updateTime(startTime);
});
}
usingSet() {
const startTime = performance.now();
this.processing = true;
const max = this.max + this.currentId;
const updateData = {};
for (this.currentId; this.currentId <= max; ++this.currentId) {
updateData[this.currentId] = {text: 'Milk'};
}
this.groceriesObject.set(updateData)
.then(() => {
this.processing = false;
this.updateTime(startTime);
});
}
private updateTime(startTime) {
const total = performance.now() - startTime;
this.totalTime = Math.round(total * 100) / 100;
}
}