Skip to content

refactor(events): type the dispatched event (drop the any bag)#72

Merged
bigmistqke merged 1 commit into
solidjs-community:nextfrom
bigmistqke:refactor/typed-event
Jun 7, 2026
Merged

refactor(events): type the dispatched event (drop the any bag)#72
bigmistqke merged 1 commit into
solidjs-community:nextfrom
bigmistqke:refactor/typed-event

Conversation

@bigmistqke

Copy link
Copy Markdown
Contributor

An architecture-review deepening: the event Pointer dispatches to handlers had almost no type depth — createThreeEvent returned a bag, then move/dispatch/click/propagate re-typed it any (7 casts) and grew it by mutation (currentObject/currentIntersection per node, capture methods bolted on, plugin extra Object.assign'd).

Change

  • Introduce DispatchEvent<TExtra> — the writable shape the Pointer assembles (optional event fields + Partial<PointerCapture> + typed extra).
  • createThreeEvent returns it and merges a typed extra; dispatch<TExtra> is generic.
  • The dispatch path is now fully typed — no any on the event — and a plugin source's extra fields (e.g. the XR controller payload) are type-checked instead of merged blind. Handlers still receive the precise public ThreeEvent via their prop types.

Notes

Test plan

  • pnpm lint + pnpm build green.
  • Browser suite green — 215 passed (incl. the new createThreeEvent typing test).

The event Pointer dispatches was built by createThreeEvent then grown by mutation across move/dispatch/click/propagate as `event: any` (7 casts): currentObject/currentIntersection set per node, capture methods bolted on, plugin extra Object.assign'd.

Introduce a DispatchEvent<TExtra> view — the writable shape the Pointer assembles (optional event fields + Partial<PointerCapture> + typed extra). createThreeEvent returns it and merges a typed `extra`; dispatch is generic over TExtra. The dispatch path is now fully typed (no `any` on the event), and a plugin source's extra fields (e.g. the XR controller payload) are type-checked instead of merged blind. Handlers still receive the precise public ThreeEvent via their prop types; runtime behavior is unchanged.
@pkg-pr-new

pkg-pr-new Bot commented Jun 7, 2026

Copy link
Copy Markdown

commit: 71e254c

@bigmistqke bigmistqke merged commit 0c61cbc into solidjs-community:next Jun 7, 2026
2 checks passed
@bigmistqke bigmistqke deleted the refactor/typed-event branch June 7, 2026 08:52
bigmistqke added a commit to bigmistqke/solid-three that referenced this pull request Jun 7, 2026
Now that core dispatch is generic over the event's extra fields (solidjs-community#72), declare the controller's extra once as XRControllerExtra and reuse it for both the dispatch call (dispatch<XRControllerExtra>) and the handler type (XRThreeEvent = ThreeEvent<XRInputSourceEvent> & XRControllerExtra) — so the payload the source supplies and the type handlers receive can no longer drift, and the merge is type-checked instead of blind.
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