Conversation
- Updated the `useAppEvent` hook to allow for custom events with TypeScript generics, enabling users to define their own event maps without extending the base callback map. - Added documentation for custom events in the API reference and created an example demonstrating their usage. - Expanded unit tests to validate the functionality of custom events and ensure proper type safety during event registration and cleanup.
🦋 Changeset detectedLatest commit: 28e1096 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull Request Overview
This PR adds custom event map support to the useAppEvent hook, allowing developers to define and subscribe to custom application events with full TypeScript type safety. The hook now accepts generic type parameters to support user-defined events beyond the built-in PlayCanvas events.
Key changes:
- Redesigned the hook's type system to support custom event maps via generics
- Updated the event handler to accept variable arguments for custom events
- Added comprehensive documentation and examples for custom event usage
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/lib/src/hooks/use-app-event.ts | Core hook implementation with generic type support and updated event handling |
| packages/lib/src/hooks/use-app-event.test.tsx | Test cases for custom event map functionality |
| packages/docs/content/examples/custom-events.mdx | Complete example documentation for custom events usage |
| packages/docs/content/docs/api/hooks/index.mdx | Updated API documentation with custom events section |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
commit: |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Changed the callback invocation for custom events to no longer forward arguments, ensuring it is called without parameters.
Adds a Custom Event Map to
useAppEventwhich allows subscribing to user defined events. Fixes #203Tests included. Docs updated