Replace per-class toMessage() overrides with a single spread in GenericEvent - #12
Open
afreakk wants to merge 1 commit into
Open
Replace per-class toMessage() overrides with a single spread in GenericEvent#12afreakk wants to merge 1 commit into
afreakk wants to merge 1 commit into
Conversation
…icEvent
Every event subclass hand-wrote a toMessage() that re-listed its own
fields. Since all fields are enumerable own properties, a single
{ ...this } in the GenericEvent base produces the same message object;
methods live on the prototype and are not copied.
The conditional undefined-field omission in InitiateStreamEvent and
SettingsWindowEvent is dropped: no receiver distinguishes an absent key
from an undefined value (all use ?? / ternary fallbacks), and
chrome.runtime.sendMessage drops undefined values during JSON
serialization anyway.
Verified: tsc --noEmit and biome pass; Playwright e2e suite 29/30
passed (the one failure, "FPS emission requires a valid message
source", also fails on the unmodified base in this environment and is
unrelated).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0152TXW9J4VcAkvuNYn6hYBh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Removes ~120 lines of hand-written serialization boilerplate from the event/message classes. Every subclass of
GenericEventoverrodetoMessage()just to re-list its own fields; the base class now does it once with an object spread:All 12 subclass overrides are deleted (
eventMessage.ts,SetSceneEvent,SetSceneSettingsEvent,SettingsWindowEvent). Adding a field to an event class no longer requires remembering to also add it totoMessage().Why this is behavior-preserving
{ ...this }produces the same message object; methods live on the prototype and are not copied.InitiateStreamEventandSettingsWindowEventpreviously omitted anundefinedsourcekey; the spread keeps it assource: undefined. No receiver distinguishes the two — every reader uses.sourcewith??/ternary fallbacks (offscreenWindow/main.ts:128,background.ts:140,sandbox/main.ts:113), andchrome.runtime.sendMessagedropsundefinedvalues during JSON serialization anyway.Verification
pnpm run compile(tsc) andpnpm run lint(biome) pass.No overlap with
drop-sandbox-iframe-butterchurn3— that branch doesn't touch these files.🤖 Generated with Claude Code
https://claude.ai/code/session_0152TXW9J4VcAkvuNYn6hYBh
Generated by Claude Code