Open
Conversation
The raw wasm-bindgen output has three usability problems that every consumer ends up working around on their own: 1. process() returns bare undefined while the model is warming up, with no way to distinguish "buffering" from an error or to know how many more samples are needed. 2. min_samples() exists but there is no way to query progress toward it — callers have to track sample counts externally. 3. Every process() call returns a heap-allocated WASM result object. Forgetting .free() leaks silently; FinalizationRegistry is registered but non-deterministic. This commit adds three wrapper classes (AlphaBumpDetector, AlphaPeakModel, CalmnessModel) and a band_powers_relative() helper that fix all three issues: - process() returns NotReady | <Reading> — a discriminated union where NotReady carries samplesNeeded so callers always know why they got no result. - .samplesBuffered and .samplesNeeded are tracked automatically. - WASM result objects are extracted into plain JS objects and freed in a try/finally, so callers never touch heap-allocated results. The raw WASM classes are still re-exported from index.ts for low-level access, so this is fully non-breaking.
- Extend eeg_wasm mock with WASM model/result classes - Add models.test.ts covering NotReady discriminated union, sample tracking, reset, Symbol.dispose, and band_powers_relative - Export models from index.ts
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AlphaBumpDetector,AlphaPeakModel,CalmnessModelwrapper classes andband_powers_relative()over the raw wasm-bindgen outputprocess()now returnsNotReady | <Reading>instead of bareundefined—NotReadycarriessamplesNeededso callers always know why they got no result.samplesBuffered/.samplesNeededtry/finally— callers never handle heap-allocated resultsMotivation
Feedback from a downstream consumer (tradelock) who had to build their own accumulator on top because
process()gave no signal on why it returnedundefined, and hit silent memory leaks from unfreed result objects.Test plan
pnpm testpasses inpackages/eeg-webNotReadypath returns correctsamplesNeeded.free()needed)Want me to swap in the actual downstream link or adjust the tone?