feature(lambda-rs): Refactor the current event system to allow components to only implement handlers for events they care about #94
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
Replace the monolithic
Component::on_evententry point with opt-in per-categoryevent handlers (
on_window_event,on_keyboard_event, etc.) and introduceEventMaskfor O(1) event filtering at the runtime level. This reducesboilerplate pattern matching in components and allows runtimes to skip dispatch
for components that do not declare interest in a given event category.
Related Issues
Changes
EventMaskbitmask type with category constants (WINDOW,KEYBOARD,MOUSE,RUNTIME,COMPONENT) andcontains/unionoperationsEvents::mask()method to map event variants to their categoryComponent::on_eventfrom the public APIComponent::event_mask()with default returningEventMask::NONEon_*_eventhandlers with default no-op implementationsApplicationRuntimeto filter dispatch usingEventMaskdocs/rendering.mdwith new component examplesEventMaskbehavior and runtime dispatch filteringDefaultderive toEventMaskfor convenienceType of Change
Affected Crates
lambda-rslambda-rs-platformlambda-rs-argslambda-rs-loggingChecklist
cargo +nightly fmt --all)cargo clippy --workspace --all-targets -- -D warnings)cargo test --workspace)Testing
Commands run:
cargo build --workspace cargo test --workspace cargo +nightly fmt --all cargo clippy --workspace --all-targets -- -D warningsManual verification steps (if applicable):
cargo run -p lambda-rs --example minimalcargo run -p lambda-rs --example trianglecargo run -p lambda-rs --example reflective_roomreflective_roomexampleScreenshots/Recordings
N/A - No visual changes; API refactor only.
Platform Testing
Additional Notes
Breaking Change Migration
Components must migrate from
on_eventto the new per-category handlers:Before:
After:
Key API Changes
Component::on_event(&mut self, event: Events)Component::event_mask(&self) -> EventMaskComponent::on_window_event(&mut self, event: &WindowEvent)Component::on_keyboard_event(&mut self, event: &Key)Component::on_mouse_event(&mut self, event: &Mouse)Component::on_runtime_event(&mut self, event: &RuntimeEvent)Component::on_component_event(&mut self, event: &ComponentEvent)Performance
event_mask()does not include theevent category, reducing unnecessary handler invocations
EventMaskis au8bitmask with#[repr(transparent)], ensuring minimaloverhead for the filtering check