@webreflection/dispatch
v0.1.2
Published
A utility to dispatch common events on EventTarget references or contexts
Maintainers
Readme
@webreflection/dispatch
Social Media Photo by Mika Baumeister on Unsplash
Small utility to dispatch native Event or CustomEvent (when options includes detail) on an EventTarget. The return value is the same as dispatchEvent: false if the event was canceled, otherwise true.
Call shapes
dispatch(target, type, options?)— explicit target;thisis ignored.dispatch(type, options?)— target isthiswhen set via.call/.apply/.bind(target); otherwisethisis usuallyundefinedin modules and the implementation usesglobalThis(e.g.windowin browsers).
Invalid arity, non-string type, or a non-EventTarget target throws TypeError with a clear message. Types and full overload/this behavior are in index.d.ts; behavior is exercised in test.js.
Performance
For hot paths where arguments are already validated, use the same API without those checks:
import dispatch from '@webreflection/dispatch/fast';
// alias:
import dispatch from '@webreflection/dispatch/yolo';dispatch/fast and dispatch/yolo are the same module; prefer whichever name fits your codebase. Only use them when you guarantee correct (target, type, options?) usage.
