Skip to content

Generate WindowEvent-to-EventSlot dictionary in window events generator#35

Merged
zxyao145 merged 1 commit into
refactor/module-10.0.0from
codex/generate-dictionary-for-windowevent
Mar 10, 2026
Merged

Generate WindowEvent-to-EventSlot dictionary in window events generator#35
zxyao145 merged 1 commit into
refactor/module-10.0.0from
codex/generate-dictionary-for-windowevent

Conversation

@zxyao145
Copy link
Copy Markdown
Owner

Motivation

  • Replace individual generated backing fields per window event with a single lookup to simplify generated code and reduce duplication.
  • Support both single-argument and two-argument window event handler signatures via a common dictionary-backed slot abstraction.
  • Make generated add/remove accessors and JS-invokable callbacks resolve slots at runtime to centralize slot storage and casting.

Description

  • Updated the source generator WindowEventsGenerator to emit a single private readonly Dictionary<WindowEvent, EventSlot> _eventSlots and populate it with EventSlot<...> instances for each discovered event instead of generating one field per event (src/BQuery.SourceGenerators/WindowEventsGenerator.cs).
  • Changed generated event accessors and [JSInvokable] callback code to resolve the correct slot from _eventSlots and cast to the appropriate EventSlot<...> before adding/removing handlers or invoking (src/BQuery.SourceGenerators/WindowEventsGenerator.cs).
  • Extended BqEvents to include a non-generic EventSlot base type and a new EventSlot<T1, T2> implementation alongside existing EventSlot<T> so dictionary values can represent both one-arg and two-arg event signatures (src/BQuery/BqEvents.cs).
  • Removed the previous per-event SlotName generation and switched to dictionary-keyed slot lookup in generated output (src/BQuery.SourceGenerators/WindowEventsGenerator.cs and src/BQuery/BqEvents.cs).

Testing

  • Ran git diff --check as a quick validation of working-tree changes and it succeeded.
  • Ran repository inspections (git status, file diffs) to verify the intended changes were staged and present.
  • Attempted to run dotnet build to validate the generator in a real build but it could not be executed in this environment because dotnet is not installed (bash: command not found: dotnet).

Codex Task

@zxyao145 zxyao145 merged commit de30d3a into refactor/module-10.0.0 Mar 10, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +169 to +171
builder.Append(" [WindowEvent.")
.Append(windowEvent.MemberName)
.Append("] = new EventSlot<")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant