Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/app/fit-track/fit-track.component.ts
  • Loading branch information
jrsmth-tier2 committed Dec 11, 2023
2 parents 56a088e + 814b028 commit 51354e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 0 additions & 2 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';

import { routes } from './app.routes';
import { provideClientHydration } from '@angular/platform-browser';
import { provideHttpClient, withFetch } from "@angular/common/http";

export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideClientHydration(),
provideHttpClient(withFetch()),
]
};
27 changes: 18 additions & 9 deletions src/app/fit-track/fit-track.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Component, computed, effect, OnInit, signal, WritableSignal} from '@angular/core';
import { Component, computed, effect, OnInit, signal, WritableSignal } from '@angular/core';
import { CommonModule } from '@angular/common';
import {faHandPointer, faFutbol, faHeartbeat} from "@fortawesome/free-solid-svg-icons";
import {FaIconComponent} from "@fortawesome/angular-fontawesome";
import {FitTrackService} from "./fit-track.service";
import {Week} from "../model/week";
import {AddWeekComponent} from "./add-week/add-week.component";
import {VisualisationComponent} from "./visualisation/visualisation.component";
import { faHandPointer, faFutbol, faHeartbeat } from "@fortawesome/free-solid-svg-icons";
import { FaIconComponent } from "@fortawesome/angular-fontawesome";
import { FitTrackService } from "./fit-track.service";
import { Week } from "../model/week";
import { AddWeekComponent } from "./add-week/add-week.component";
import { VisualisationComponent } from "./visualisation/visualisation.component";
import { OrderWeeksPipe } from '../core/pipes/order-weeks.pipe';

@Component({
Expand Down Expand Up @@ -37,6 +37,16 @@ export class FitTrackComponent implements OnInit {
}

ngOnInit(): void {
// XXX: Using 'await' and then setting, may well be more performant and can avoid memory leaks.
/* e.g.
```
const historicalWeeks: Week[] = await this.fitTrackService.getHistoricalWeeks(); // No need for the extra 'then'
this.weeks.set(historicalWeeks);
```
If you are going to 'subscribe', then really you should store that subscription in a variable and remember to
unsubscribe in the destroy function.
*/

this.fitTrackService.getHistoricalWeeks().subscribe((weeks) => {
console.log(`[init] Loaded [${weeks.length}] historical weeks ... setting this.weeks()`);
this.weeks.set(weeks);
Expand All @@ -49,14 +59,13 @@ export class FitTrackComponent implements OnInit {
*/
onWeekAdded(week: any): void {
console.log(`[onWeekAdded] Callback triggered, update weeks`);
this.weeks.update(weeks => [week,...weeks]);
this.weeks.update(weeks => [week, ...weeks]);
// Note :: change detection occurs when the reference tracked by the signal changes, not simply the value in memory
}

calculateTotalMiles(): number {
console.log(`[calculateTotalMiles] calculating ..`)
let n = this.weeks().map(a => a.volume);

let miles = 0;
if (n.length > 0) {
miles = n.reduce(
Expand Down

0 comments on commit 51354e8

Please sign in to comment.