Skip to content

Add usage examples for reactive operators #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

banchan86
Copy link
Contributor

@banchan86 banchan86 commented Mar 22, 2025

Partially addresses bonsai-rx/roadmap#15

Progress

37/100 Bonsai.Reactive operators (I am not sure all of them need examples)
The examples have been updated with the VisualizerWindow from Bonsai 2.9.0
Operators covered (click on operator link for online preview - some might not be up yet till I update the demo branch):

Operator Category Basic Example Application Examples Alternatives
Accumulate Quantitative Sum
Average Quantitative Signal Smoothing
Count Quantitative ElementIndex
Min Quantitative
Max Quantitative
Sum Quantitative Accumulate
CombineLatest Combine Video Synchronization WithLatestFrom
Concat Combine Stimulus Composition Merge
Merge Combine Input Aggregation Zip
CombineLatest
WithLatestFrom
Concat
WithLatestFrom Combine Video Synchronization
Background Subtraction
CombineLatest
Zip Combine Combine Processing Results
Combine Related Events
Sample Preloaded Sequences
WithLatestFrom
CombineLatest
Gate Dynamic Filter GateInterval
WindowTrigger
BufferTrigger
Sample Dynamic Filter SampleInterval
Zip
SkipUntil Dynamic Filter Start Video Recording SubscribeWhen
SubscribeWhen Dynamic Filter SkipUntil
TakeUntil Dynamic Filter Stop Video Recording
Condition Filter
Distinct Filter DistinctUntilChanged
DistinctUntilChanged Filter Signal State Transitions
First Filter Take
FirstOrDefault
FirstOrDefault Filter Take
Last Filter TakeLast
LastOrDefault
LastOrDefault Filter TakeLast
Slice Filter Deinterleave Video Frames GateInterval
Skip Filter Discard Startup Elements Slice
SkipLast Filter Delay
Take Filter First
TakeLast Filter Last
CreateTimestamped Temporal *
Delay Temporal DelaySubscription
DelaySubscription Temporal Delay
GateInterval Temporal SampleInterval
Slice
Gate
SampleInterval Temporal GateInterval
Slice
Sample
Throttle Temporal *
Timer Temporal
TimeInterval Temporal
Timestamp Temporal Record Data Timestamps

General Issues

  • Haven't decided whether to add higher-order examples.
  • In many cases, I think the description for the basic example closely mirrors the editor description for the operator, so I might just take those out and leave only descriptions for the application examples. I will probably leave it for one of the last edits so it can be reversed if necessary.
  • The section that follows that follows with the class declaration code snippet, inheritance and inherited members does not have a section heading. That makes it seem to be a part of the examples or application examples. I think adding a section heading is needed, but I will also probably add it as an edit near the end.
  • Some reactive operators already have a section talking about alternatives and even some example workflows, was not sure if I should merge them with the new sections I am adding.

Operator-specific Issues (*)

  • For Throttle, it was hard to build a basic example using just Bonsai.Core reactive operators, since it relies on an input with variable rate, so I used KeyDown as an input.
  • CreateTimestamped was renamed from CombineTimestamp but the accompanying doc files were not updated yet, these files were renamed. In addition, the existing example (to carry forward the timestamp) was adopted as a basic example. While it is more like an application example, I could not figure out how to generate a basic example without copying much of that workflow. In addition, a true basic example for this operator would rely on timestamps coming from a different source.

@banchan86 banchan86 requested a review from glopesdev March 22, 2025 17:20
@banchan86 banchan86 added the documentation Improvements or additions to documentation label Mar 22, 2025
@banchan86 banchan86 changed the title Add usage examples for reactive quantitative operators Add usage examples for reactive operators Apr 3, 2025
@banchan86
Copy link
Contributor Author

I updated this PR with the feedback from DCM and added another batch of reactive operators (operators that "combine" sequences). As such i changed the title of this PR and also added a chart in the top level comment to document which operators were included.

Other changes that were made:

  • Switched basic types in basic examples to those from Bonsai.Core (Range/Int/Timer)
  • Separated "basic examples" from "practical application examples"
    • One point we discussed was whether to even include practical/complex examples or leave them out. As I was covering the "combine" operators however, I discovered that there was already some mention of practical applications for the operators in the overwrite articles. Distinguishing between those operators was also hard with just basic examples. Thus, I opted to include practical examples/applications for them by simply expanding on those existing notes with workflow containers.
  • Improved visualization of operators that only emit a final value by repeating the block
    • I noticed that the previous solution of using a delay node and a note to use ObjectTextVisualizer was very clunky and unintuitive.

@banchan86 banchan86 force-pushed the reactive-usage-quantitative branch from 3af2eef to 7982cd0 Compare July 15, 2025 04:17
Also updated existing example and text
Fix CreateTimestamped SVG dark mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant