Skip to content

Decouple interaction events - #55

Merged
nixonyh merged 6 commits into
mainfrom
nixon/decouple-interaction-events
Jun 17, 2026
Merged

Decouple interaction events#55
nixonyh merged 6 commits into
mainfrom
nixon/decouple-interaction-events

Conversation

@nixonyh

@nixonyh nixonyh commented Jun 17, 2026

Copy link
Copy Markdown
Member

Interaction handlers now take in &mut W world as opposed to &mut Events.
Events are meant to be opt-in, and can be used when the backend world does not have any event system at all.

nixonyh added 5 commits June 17, 2026 20:37
Move per-element interaction handlers into the element table, keyed by
ElementId, mirroring watches and bindings, and decouple them from the
event queue.

- Delete the standalone `Interactions` store (it was just a
  `TypeTable<ElementId>` wrapper); handlers now ride the element table
  as `HandlerFn<I, W>` components, one per `(element, I)`, dropped with
  the element via `remove_row`.
- Decouple handlers from `Events`: a handler is now `fn(I, &mut W)` and
  mutates the world directly. `Fynix::dispatch` takes `&mut W` and the
  unused `events` field is removed.
- Drop the now-dead `fynix_event` and `sparse_map` dependencies.
- Add binding tests; fix the element-table component test to use the
  new `IdGenerator` helper.
- Rename `Watch` to `Watcher`
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@nixonyh, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 3 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 48140f1c-3c3f-4260-b3dd-43c469773165

📥 Commits

Reviewing files that changed from the base of the PR and between ba7d952 and 0d2ce59.

📒 Files selected for processing (1)
  • crates/fynix/src/reactive/binding.rs
📝 Walkthrough

Walkthrough

The PR refactors fynix's runtime to be generic over a world type W: 'static. ElementTable gains reactive columns for Watcher<W> and Binding<W> and splits into RenderElementTable/LayoutElementTable views. The interaction model drops Events/Interactions in favor of HandlerFn<I, W> that directly mutates W. Watch/WatchElement are renamed to Watcher/WatcherElement, Binding::build becomes apply with conditional dirty-marking, and Fynix::dispatch now accepts world: &mut W.

Changes

World-typed reactive runtime refactor

Layer / File(s) Summary
ElementTable<W> generics, reactive columns, and table adapters
crates/fynix/src/element/table.rs, crates/fynix/src/element/storage.rs, crates/fynix/src/element/layout.rs, crates/fynix/src/element.rs
ElementTable is parameterized over W: 'static with new watch_col/binding_col columns and insert_watcher/insert_binding methods; table access is split into RenderElementTable and LayoutElementTable views; Elements<W> and ElementNodes are updated to use the new generic and view types.
Watch→Watcher rename and reactive module restructuring
crates/fynix/src/reactive/watcher.rs, crates/fynix/src/reactive.rs
WatchElementWatcherElement, Watch<W>Watcher<W>, rebuild takes id by reference; pub mod watch replaced by pub mod watcher; docs and tests updated throughout.
Binding::apply with conditional dirty marking
crates/fynix/src/reactive/binding.rs
Binding::build renamed to apply; internal ApplyFn now returns bool so dirty marking only occurs on successful writes; Binding<W> tightened to W: 'static; test suite added for conditional updates, instance scoping, and stale-binding-after-remove.
HandlerFn<I,W> world mutation model and Interactions removal
crates/fynix/src/interaction.rs
HandlerFn<I> changed to HandlerFn<I, W> for direct world mutation; Interactions store and Events dispatch removed; test suite rewritten using World { clicks } with bubbling and gate-closure coverage.
Fynix<W> runtime: dispatch, dispatch_bubbling, sync, remove_element
crates/fynix/src/lib.rs
Fynix<W> drops events/interactions/_world fields; dispatch takes world: &mut W and resolves HandlerFn<I, W> from the element table; dispatch_bubbling added for parent-chain traversal; sync iterates changed Watcher<W> and Binding<W> components; remove_element simplified.
FynixCtx/ElementCtx API updates: watch, bind, on
crates/fynix/src/ctx.rs
FynixCtx<W> and ElementCtx<W> tightened to W: 'static; watch builds a WatcherElement holder via insert_watcher; bind wires through insert_binding; on inserts HandlerFn<I, W> directly as an element component.
Consumer crate updates
crates/fynix/Cargo.toml, crates/fynix_elements/src/lib.rs, crates/fynix_hit_test/src/lib.rs
Button/Label render methods updated to RenderElementTable; HitTest::build made generic over W: 'static; Cargo deps swap fynix_event/sparse_map for fynix_macros/typarena/rectree.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Fynix
  participant ElementTable
  participant HandlerFn
  participant Watcher
  participant Binding

  rect rgba(70, 130, 180, 0.5)
    Note over Caller,HandlerFn: Interaction dispatch
    Caller->>Fynix: dispatch(id, interaction, &mut world)
    Fynix->>ElementTable: component::<HandlerFn<I,W>>(id)
    ElementTable-->>Fynix: Some(handler)
    Fynix->>HandlerFn: handler(interaction, &mut world)
    HandlerFn-->>Caller: world mutated
  end

  rect rgba(60, 179, 113, 0.5)
    Note over Caller,Binding: Reactive sync
    Caller->>Fynix: sync(&mut world)
    Fynix->>ElementTable: components::<Watcher<W>>()
    loop each watcher where is_changed(world)
      Fynix->>Watcher: rebuild(&id, fynix, world)
    end
    Fynix->>ElementTable: components::<Binding<W>>()
    loop each binding where is_changed(world)
      Fynix->>Binding: apply(&id, &mut elements, world)
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • voxell-tech/fynix#41: This PR directly removes the Interactions store and Events-based HandlerFn that #41 introduced, replacing them with the new world-mutation dispatch model.
  • voxell-tech/fynix#52: This PR integrates the Binding/apply reactive system introduced in #52 into ElementTable<W> columns and the Fynix::sync loop.
  • voxell-tech/fynix#53: Both PRs refactor Watch/Binding into per-element ElementTable components with the W: 'static generic, sharing the same sync reconciliation path.

Suggested reviewers

  • ian-hon
  • Sheerwin02

🐇 The watch has become a watcher, hooray!
The world gets mutated the direct way.
No more events in a queue to dispatch,
Just handlers and tables, a perfect match.
apply marks dirty when writes succeed—
This bunny approves of each generic deed! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Decouple interaction events' directly reflects the main change: interaction handlers are decoupled from the event system and now take &mut W instead of &mut Events.
Description check ✅ Passed The description is directly related to the changeset, explaining that interaction handlers now take &mut W world instead of &mut Events, and that Events become opt-in.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/fynix/src/reactive/binding.rs`:
- Around line 101-103: The doc comment for the function around lines 101-103
states that the element is "still marked dirty" on a no-op write when the
element is absent or of a different type, but this contradicts the actual
implementation where the function returns false in those cases and the apply()
method only marks the element dirty when success is true. Update the doc comment
to accurately reflect that no-op writes do NOT result in marking the element
dirty, removing the claim about marking dirty on absent or type-mismatch
scenarios.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c829da56-1060-4d9b-ae85-2e00a9a096ea

📥 Commits

Reviewing files that changed from the base of the PR and between 660e860 and ba7d952.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • crates/fynix/Cargo.toml
  • crates/fynix/src/ctx.rs
  • crates/fynix/src/element.rs
  • crates/fynix/src/element/layout.rs
  • crates/fynix/src/element/storage.rs
  • crates/fynix/src/element/table.rs
  • crates/fynix/src/interaction.rs
  • crates/fynix/src/lib.rs
  • crates/fynix/src/reactive.rs
  • crates/fynix/src/reactive/binding.rs
  • crates/fynix/src/reactive/watcher.rs
  • crates/fynix_elements/src/lib.rs
  • crates/fynix_hit_test/src/lib.rs
💤 Files with no reviewable changes (1)
  • crates/fynix/Cargo.toml

Comment thread crates/fynix/src/reactive/binding.rs Outdated
@nixonyh
nixonyh merged commit b323778 into main Jun 17, 2026
8 checks passed
@nixonyh
nixonyh deleted the nixon/decouple-interaction-events branch June 17, 2026 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant