-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
15 changes: 9 additions & 6 deletions
15
src/app/pages/statistics-page/statistics-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
<highcharts-chart | ||
[Highcharts]="Highcharts" | ||
[constructorType]="chartConstructor" | ||
[options]="chartOptions" | ||
class="block h-full w-full" | ||
></highcharts-chart> | ||
@if (chartOptions(); as chartOptions) { | ||
<highcharts-chart | ||
[Highcharts]="Highcharts" | ||
[constructorType]="chartConstructor" | ||
[options]="chartOptions" | ||
[update]="updateFlag" | ||
class="block h-full w-full" | ||
></highcharts-chart> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Signal, effect, signal } from '@angular/core'; | ||
import { Observable, Subscription } from 'rxjs'; | ||
|
||
export function computedAsync<T>( | ||
computation: () => Observable<T>, | ||
): Signal<T | null> & { recompute: () => void } { | ||
const sig = signal<T | null>(null); | ||
|
||
// Save current subscription to be able to unsubscribe | ||
let subscription: Subscription; | ||
|
||
// Create an arrow function that contains the signal updating logic | ||
const recompute = () => { | ||
sig.set(null); | ||
// Before making the new subscription, unsub from the previous one | ||
if (subscription && !subscription.closed) { | ||
subscription.unsubscribe(); | ||
} | ||
const observable = computation(); | ||
subscription = observable.subscribe((result) => sig.set(result)); | ||
}; | ||
|
||
effect(recompute, { allowSignalWrites: true }); | ||
|
||
// Add the recompute function to the returned signal, so that it can be called from the outside | ||
return Object.assign(sig, { recompute }); | ||
} |