Skip to content

Replace tiny-emitter package with inline ESM implementation#3653

Open
andreialecu wants to merge 1 commit intojosdejong:developfrom
andreialecu:replace-tiny-emitter-with-esm
Open

Replace tiny-emitter package with inline ESM implementation#3653
andreialecu wants to merge 1 commit intojosdejong:developfrom
andreialecu:replace-tiny-emitter-with-esm

Conversation

@andreialecu
Copy link
Copy Markdown

Summary

  • Replaces the CommonJS-only tiny-emitter dependency with an inline ESM implementation
  • Eliminates the "Module 'tiny-emitter' is not ESM" warning in Angular and other ESM-first bundlers
  • Enables proper tree-shaking of this code

Part of #3649 — this is the last of the four CommonJS dependencies (seedrandom, escape-latex, javascript-natural-sort, tiny-emitter).

Details

The tiny-emitter package hasn't been updated in 7+ years and only ships CommonJS. Rather than waiting for an upstream ESM build, this inlines the implementation directly into the existing emitter.js wrapper.

The new implementation is actually simpler than the original wrapper — instead of creating a new Emitter() instance and .bind()-ing four methods, the on/off/once/emit methods are defined directly as closures over a private events object. This keeps the events map fully encapsulated (the old wrapper had a comment noting it wanted to hide emitter.e).

Test plan

  • New unit tests for the emitter module (16 tests: subscribe, context, once, arguments, off by name/callback, duplicate listeners, once+off, emit before subscribe, unsubscribe during emit, chaining)
  • All 6658 unit tests pass
  • Lint passes with zero warnings

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant