Generate WindowEvent-to-EventSlot dictionary in window events generator#35
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20b211b5a1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| builder.Append(" [WindowEvent.") | ||
| .Append(windowEvent.MemberName) | ||
| .Append("] = new EventSlot<") |
There was a problem hiding this comment.
Prevent duplicate WindowEvent keys in generated slot map
Generating _eventSlots with WindowEvent keys causes a runtime ArgumentException when two declared events compare equal, which already happens in this repo (OnDoubleClick and OnClick both have name "click", and WindowEvent.Equals compares by Name case-insensitively). Because the dictionary is initialized in the BqEvents instance initializer, constructing BqEvents will fail before any handlers can be used.
Useful? React with 👍 / 👎.
Motivation
Description
WindowEventsGeneratorto emit a singleprivate readonly Dictionary<WindowEvent, EventSlot> _eventSlotsand populate it withEventSlot<...>instances for each discovered event instead of generating one field per event (src/BQuery.SourceGenerators/WindowEventsGenerator.cs).[JSInvokable]callback code to resolve the correct slot from_eventSlotsand cast to the appropriateEventSlot<...>before adding/removing handlers or invoking (src/BQuery.SourceGenerators/WindowEventsGenerator.cs).BqEventsto include a non-genericEventSlotbase type and a newEventSlot<T1, T2>implementation alongside existingEventSlot<T>so dictionary values can represent both one-arg and two-arg event signatures (src/BQuery/BqEvents.cs).SlotNamegeneration and switched to dictionary-keyed slot lookup in generated output (src/BQuery.SourceGenerators/WindowEventsGenerator.csandsrc/BQuery/BqEvents.cs).Testing
git diff --checkas a quick validation of working-tree changes and it succeeded.git status, file diffs) to verify the intended changes were staged and present.dotnet buildto validate the generator in a real build but it could not be executed in this environment becausedotnetis not installed (bash: command not found: dotnet).Codex Task