Poprawki wydajności

This commit is contained in:
2022-10-17 16:28:07 +02:00
parent 83aa054a70
commit c395340054
3 changed files with 33 additions and 33 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
index.html,1665605211157,71f3e676d9ddbcafd2a6e4773a9c2a757a0bd51e884f632dbe7351c16b2f9674
logo.svg,1665605133131,6441e7d33cf714ef1cb9dc7fbb816cf2f5340d343ef518f7856619002f1ab48e
assets/index.cbb2a49f.css,1665605211157,f02460bf3d64c35cf17b4c9e9c46a7d9d32680d22b006d76bfda4e0abb31b5be
assets/index.83548fb0.js,1665605211157,c2fb42de2fa35be75163458fd213617b9c60e168a32bb524d42ff3d7ceb72e25
index.html,1665943324670,eedf202dd40bfb0b5d15ff62c816e85f3686ec79b5fc832e80a9bc4d6e87b463
assets/index.3c31aafa.css,1665943324675,3721eea2e25edd61839ae6acd54ec12bc8a39334ef5698a504f97b0df4e8ee3e
assets/index.d0562efe.js,1665943324675,b22ce921d90c2cd0ff6b197ebf59e5815cd8f645c4fe6625738ef03645b33279
+2 -3
View File
@@ -2,9 +2,8 @@ interface ITableRowValues {
routeTo: string;
routeVia: string;
currentRouteToIndex: number;
currentRouteViaIndex: number;
currentDateDigitIndex: number;
// routeTo, routeVia, date1, date2, date3, date4
currentRowIndexes: [number, number, number, number, number, number];
dateDigits: string[],
}
+20 -19
View File
@@ -128,9 +128,7 @@ const departureInfoEmptyObj: ITableRow = {
routeTo: '',
routeVia: '',
currentRouteToIndex: 0,
currentRouteViaIndex: 0,
currentDateDigitIndex: 0,
currentRowIndexes: [0, 0, 0, 0, 0, 0],
dateDigits: ['', '', '', ''],
},
@@ -153,7 +151,7 @@ export default defineComponent({
apiTrainData: [] as ITrainResponse[],
animationFrameIndex: 0,
isAnimationRunning: true,
intervalIndex: 0,
lastRefreshTime: 0,
@@ -183,11 +181,13 @@ export default defineComponent({
this.fetchDepartureList();
}, 30000);
this.animationFrameIndex = requestAnimationFrame(this.update);
this.isAnimationRunning = true;
requestAnimationFrame(this.update);
},
deactivated() {
cancelAnimationFrame(this.animationFrameIndex);
this.isAnimationRunning = false;
clearInterval(this.intervalIndex);
},
@@ -250,9 +250,7 @@ export default defineComponent({
routeTo: '',
routeVia: '',
dateDigits: ['', '', '', ''],
currentRouteToIndex: 0,
currentRouteViaIndex: 0,
currentDateDigitIndex: 0,
currentRowIndexes: [0, 0, 0, 0, 0, 0],
},
});
@@ -326,6 +324,8 @@ export default defineComponent({
},
update(time: number) {
if (!this.isAnimationRunning) return;
if (time >= this.lastRefreshTime + 125) {
this.updateTableRows();
@@ -342,25 +342,26 @@ export default defineComponent({
updateTableRows() {
this.departureTable.forEach((dep, i) => {
if (dep.tableValues.routeTo.toLowerCase() != dep.routeTo.toLowerCase()) {
dep.tableValues.routeTo = this.departureRoutes[dep.tableValues.currentRouteToIndex];
dep.tableValues.routeTo = this.departureRoutes[dep.tableValues.currentRowIndexes[0]];
dep.tableValues.currentRouteToIndex = (dep.tableValues.currentRouteToIndex + 1) % this.departureRoutes.length;
dep.tableValues.currentRowIndexes[0] =
(dep.tableValues.currentRowIndexes[0] + 1) % this.departureRoutes.length;
}
if (dep.tableValues.routeVia.toLowerCase() != dep.routeVia.toLowerCase()) {
dep.tableValues.routeVia = this.departureRoutes[dep.tableValues.currentRouteViaIndex];
dep.tableValues.routeVia = this.departureRoutes[dep.tableValues.currentRowIndexes[1]];
dep.tableValues.currentRouteViaIndex =
(dep.tableValues.currentRouteViaIndex + 1) % this.departureRoutes.length;
dep.tableValues.currentRowIndexes[1] =
(dep.tableValues.currentRowIndexes[1] + 1) % this.departureRoutes.length;
}
dep.tableValues.dateDigits.forEach((digit, j) => {
if (dep.dateDigits[j] != digit)
dep.tableValues.dateDigits[j] = this.dateDigits[dep.tableValues.currentDateDigitIndex];
if (dep.dateDigits[j] != digit) {
dep.tableValues.dateDigits[j] = this.dateDigits[dep.tableValues.currentRowIndexes[j + 2]];
dep.tableValues.currentRowIndexes[j + 2] =
(dep.tableValues.currentRowIndexes[j + 2] + 1) % this.dateDigits.length;
}
});
// Poprawić do wszystkich
dep.tableValues.currentDateDigitIndex = (dep.tableValues.currentDateDigitIndex + 1) % this.dateDigits.length;
});
},