mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-14 18:01:20 +08:00
9e87de9c5f
Addresses the simplify pass on #325: - Replaced `createImageDecodeBinder` factory + interface + `size()` method with a plain `bindImageDecodes(ctx)` function. The factory wrapped a 20-LOC helper in a closure whose only benefit was test introspection — and that introspection was only ever the `size()` getter, which duplicates what `Set.size` on the caller-owned bound set already provides. - The caller now owns the `bound` set. Production uses `WeakSet` so removed `<img>` elements can be garbage-collected; tests pass `Set` when they want `.has()` introspection. Earlier revision used `Set` unconditionally and claimed in a comment that this was fine because the bitmap cache evicts on its own — that reasoning was wrong, the `Set` entry keeps the whole DOM node GC-rooted. - Listener cleanup uses an `AbortSignal` wired to the runtime's cleanup registry. `{ once: true }` alone only cleaned up after the event fired; if an `<img>` was removed before ever loading (common on sub-composition unmount), the listener closure leaked. The signal detaches the listener deterministically on runtime teardown. - Dropped the `addEventListener` dependency injection. The only non-default caller was the test, and rewriting the test to assert against the stub's own `addEventListener` mock is simpler than threading an injection through the production path. - Dropped the `tornDown` callback in favour of the signal — same purpose, one mechanism. - Removed the `img.decoding !== "async"` guard. Setting a DOM string attribute to its existing value is a browser-level no-op; the check cost more than the assignment. - Trimmed the file header and function JSDocs from ~30 lines to a tight 10-line block. The file header still explains the WHY; the inline comments explain subtle points at the call site. - Test file slimmed from 9 verbose cases to 5 meaningful ones. The dropped cases were trivially asserting a single assignment (`decoding='async'`), collapsing duplicates ("binds multiple imgs" + "picks up new imgs" exercised the same path), and the swallowed-rejection case had no real assertion — its only verification was a comment claiming the `await Promise.resolve()` shape proved something. No behaviour change in preview. 5/5 tests pass, typecheck clean.