summaryrefslogtreecommitdiff
path: root/web-timeplot/src/data/source-registry.js
diff options
context:
space:
mode:
authorThomas Grothe <grothe.tr@gmail.com>2026-04-30 00:53:13 -0400
committerThomas Grothe <grothe.tr@gmail.com>2026-04-30 00:53:13 -0400
commit73d75835e18a33c7f6c1b09bbcef93b16a7a9bfa (patch)
treee079c6c45416333e29cf900831c07619a87d5c39 /web-timeplot/src/data/source-registry.js
parenta1c95e72bea26f554eb05916d6fc584927367159 (diff)
redo timeplot web
Diffstat (limited to 'web-timeplot/src/data/source-registry.js')
-rw-r--r--web-timeplot/src/data/source-registry.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/web-timeplot/src/data/source-registry.js b/web-timeplot/src/data/source-registry.js
new file mode 100644
index 0000000..06f5895
--- /dev/null
+++ b/web-timeplot/src/data/source-registry.js
@@ -0,0 +1,41 @@
+import { SyntheticWaveSource } from './synthetic-wave-source.js';
+
+export class SourceRegistry {
+ constructor(store, bus) {
+ this.store = store;
+ this.bus = bus;
+ this.sources = new Map([
+ ['synthetic-wave', new SyntheticWaveSource(store.getState().source)],
+ ]);
+ this.activeSource = this.sources.get(store.getState().source.activeId);
+ this.activeSource.start(store.getState().time.plotTimeMs);
+ }
+
+ syncFromState() {
+ const state = this.store.getState();
+ const nextSource = this.sources.get(state.source.activeId);
+
+ if (nextSource !== this.activeSource) {
+ this.activeSource?.stop();
+ this.activeSource = nextSource;
+ this.activeSource?.start(state.time.plotTimeMs);
+ }
+
+ this.activeSource?.updateConfig(state.source);
+ }
+
+ update(currentPlotTimeMs) {
+ if (!this.activeSource) {
+ return;
+ }
+
+ const points = this.activeSource.update(currentPlotTimeMs);
+ for (const point of points) {
+ this.bus.emit('data:point', point);
+ }
+ }
+
+ reset() {
+ this.activeSource?.reset(this.store.getState().time.plotTimeMs);
+ }
+}