diff options
Diffstat (limited to 'web-timeplot/src/data/source-registry.js')
| -rw-r--r-- | web-timeplot/src/data/source-registry.js | 41 |
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); + } +} |
