Update metrics selector via State
This commit is contained in:
parent
9bc96f79af
commit
3dc54738fa
3 changed files with 47 additions and 11 deletions
42
scripts/graph/state.ts
Normal file
42
scripts/graph/state.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { updateMetricsDiv } from "./metrics.js";
|
||||
import { Requests, MetricsResponse } from "./requests.js";
|
||||
|
||||
export class State {
|
||||
#requests: Requests;
|
||||
#metricsDiv: HTMLElement;
|
||||
|
||||
#updating: boolean = false;
|
||||
#metrics: MetricsResponse | null = null;
|
||||
|
||||
constructor(requests: Requests, metricsDiv: HTMLElement) {
|
||||
this.#requests = requests;
|
||||
this.#metricsDiv = metricsDiv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look at current state and try to change it so that it represents what the
|
||||
* user wants.
|
||||
*
|
||||
* This function is idempotent.
|
||||
*/
|
||||
async update() {
|
||||
if (this.#updating) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await this.#update_impl();
|
||||
} finally {
|
||||
this.#updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
async #update_impl() {
|
||||
this.#update_metrics();
|
||||
}
|
||||
|
||||
async #update_metrics() {
|
||||
this.#metrics = await this.#requests.get_metrics();
|
||||
if (this.#metrics === null) { return; }
|
||||
updateMetricsDiv(this.#metricsDiv, this.#metrics.metrics);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue