event-target-shim
- Version 6.0.2
- Published
- 390 kB
- No dependencies
- MIT license
Install
npm i event-target-shim
yarn add event-target-shim
pnpm add event-target-shim
Overview
An implementation of WHATWG EventTarget interface.
Index
Functions
Classes
Namespaces
Functions
function defineCustomEventTarget
defineCustomEventTarget: < TEventMap extends Record<string, Event<string>>, TMode extends 'standard' | 'strict' = 'standard'>( ...types: (string & keyof TEventMap)[]) => defineCustomEventTarget.CustomEventTargetConstructor<TEventMap, TMode>;
Define an
EventTarget
class that has event attibutes.Parameter types
The types to define event attributes.
Deprecated
Use
getEventAttributeValue
/setEventAttributeValue
pair on your derived class instead because of static analysis friendly.
function defineEventAttribute
defineEventAttribute: < TEventTarget extends EventTarget<Record<string, Event<string>>, 'standard'>, TEventType extends string, TEventConstrucor extends typeof Event>( target: TEventTarget, type: TEventType, _eventClass?: TEventConstrucor) => asserts target is TEventTarget & defineEventAttribute.EventAttributes< TEventTarget, Record<TEventType, InstanceType<TEventConstrucor>> >;
Define an event attribute.
Parameter target
The
EventTarget
object to define an event attribute.Parameter type
The event type to define.
Parameter _eventClass
Unused, but to infer
Event
class type.Deprecated
Use
getEventAttributeValue
/setEventAttributeValue
pair on your derived class instead because of static analysis friendly.
function getEventAttributeValue
getEventAttributeValue: < TEventTarget extends EventTarget<any, any>, TEvent extends Event<string>>( target: TEventTarget, type: string) => EventTarget.CallbackFunction<TEventTarget, TEvent> | null;
Get the current value of a given event attribute.
Parameter target
The
EventTarget
object to get.Parameter type
The event type.
function setErrorHandler
setErrorHandler: (value: setErrorHandler.ErrorHandler | undefined) => void;
Set the error handler.
Parameter value
The error handler to set.
function setEventAttributeValue
setEventAttributeValue: ( target: EventTarget<any, any>, type: string, callback: EventTarget.CallbackFunction<any, any> | null) => void;
Set an event listener to a given event attribute.
Parameter target
The
EventTarget
object to set.Parameter type
The event type.
Parameter callback
The event listener.
function setWarningHandler
setWarningHandler: (value: setWarningHandler.WarningHandler | undefined) => void;
Set the warning handler.
Parameter value
The warning handler to set.
Classes
class Event
class Event<TEventType extends string = string> {}
An implementation of
Event
interface, that wraps a given event object.EventTarget
shim can control the internal state of thisEvent
objects.See Also
https://dom.spec.whatwg.org/#event
constructor
constructor(type: string, eventInitDict?: Event.EventInit);
Initialize this event instance.
Parameter type
The type of this event.
Parameter eventInitDict
Options to initialize.
See Also
https://dom.spec.whatwg.org/#dom-event-event
property AT_TARGET
static readonly AT_TARGET: number;
See Also
https://dom.spec.whatwg.org/#dom-event-at_target
property AT_TARGET
readonly AT_TARGET: number;
See Also
https://dom.spec.whatwg.org/#dom-event-at_target
property bubbles
readonly bubbles: boolean;
true
if this event will bubble.See Also
https://dom.spec.whatwg.org/#dom-event-bubbles
property BUBBLING_PHASE
static readonly BUBBLING_PHASE: number;
See Also
https://dom.spec.whatwg.org/#dom-event-bubbling_phase
property BUBBLING_PHASE
readonly BUBBLING_PHASE: number;
See Also
https://dom.spec.whatwg.org/#dom-event-bubbling_phase
property cancelable
readonly cancelable: boolean;
true
if this event can be canceled by thepreventDefault()
method.See Also
https://dom.spec.whatwg.org/#dom-event-cancelable
property cancelBubble
cancelBubble: boolean;
true
if event bubbling was stopped.See Also
https://dom.spec.whatwg.org/#dom-event-cancelbubble
Deprecated
property CAPTURING_PHASE
static readonly CAPTURING_PHASE: number;
See Also
https://dom.spec.whatwg.org/#dom-event-capturing_phase
property CAPTURING_PHASE
readonly CAPTURING_PHASE: number;
See Also
https://dom.spec.whatwg.org/#dom-event-capturing_phase
property composed
readonly composed: boolean;
See Also
https://dom.spec.whatwg.org/#dom-event-composed
property currentTarget
readonly currentTarget: EventTarget<Record<string, Event<string>>, 'standard'>;
The event target of the current dispatching.
See Also
https://dom.spec.whatwg.org/#dom-event-currenttarget
property defaultPrevented
readonly defaultPrevented: boolean;
true
if the default behavior was canceled.See Also
https://dom.spec.whatwg.org/#dom-event-defaultprevented
property eventPhase
readonly eventPhase: number;
The current event phase.
See Also
https://dom.spec.whatwg.org/#dom-event-eventphase
property isTrusted
readonly isTrusted: boolean;
See Also
https://dom.spec.whatwg.org/#dom-event-istrusted
property NONE
static readonly NONE: number;
See Also
https://dom.spec.whatwg.org/#dom-event-none
property NONE
readonly NONE: number;
See Also
https://dom.spec.whatwg.org/#dom-event-none
property returnValue
returnValue: boolean;
true
if the default behavior will act.See Also
https://dom.spec.whatwg.org/#dom-event-returnvalue
Deprecated
Use the
defaultPrevented
proeprty instead.
property srcElement
readonly srcElement: EventTarget<Record<string, Event<string>>, 'standard'>;
The event target of the current dispatching.
See Also
https://dom.spec.whatwg.org/#dom-event-srcelement
Deprecated
Use the
target
property instead.
property target
readonly target: EventTarget<Record<string, Event<string>>, 'standard'>;
The event target of the current dispatching.
See Also
https://dom.spec.whatwg.org/#dom-event-target
property timeStamp
readonly timeStamp: number;
See Also
https://dom.spec.whatwg.org/#dom-event-timestamp
property type
readonly type: string;
The type of this event.
See Also
https://dom.spec.whatwg.org/#dom-event-type
method composedPath
composedPath: () => EventTarget[];
The event target of the current dispatching. This doesn't support node tree.
See Also
https://dom.spec.whatwg.org/#dom-event-composedpath
method initEvent
initEvent: (type: string, bubbles?: boolean, cancelable?: boolean) => void;
Deprecated
Don't use this method. The constructor did initialization.
method preventDefault
preventDefault: () => void;
Cancel the default behavior.
See Also
https://dom.spec.whatwg.org/#dom-event-preventdefault
method stopImmediatePropagation
stopImmediatePropagation: () => void;
Stop event bubbling and subsequent event listener callings.
See Also
https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
method stopPropagation
stopPropagation: () => void;
Stop event bubbling. Because this shim doesn't support node tree, this merely changes the
cancelBubble
property value.See Also
https://dom.spec.whatwg.org/#dom-event-stoppropagation
class EventTarget
class EventTarget< TEventMap extends Record<string, Event> = Record<string, Event>, TMode extends 'standard' | 'strict' = 'standard'> {}
An implementation of the
EventTarget
interface.See Also
https://dom.spec.whatwg.org/#eventtarget
constructor
constructor();
Initialize this instance.
method addEventListener
addEventListener: { <T extends string & keyof TEventMap>( type: T, callback?: EventTarget.EventListener<this, TEventMap[T]> | null, options?: EventTarget.AddOptions ): void; ( type: string, callback?: EventTarget.FallbackEventListener<this, TMode>, options?: EventTarget.AddOptions ): void; <T extends string & keyof TEventMap>( type: T, callback: EventTarget.EventListener<this, TEventMap[T]>, capture: boolean ): void; ( type: string, callback: EventTarget.FallbackEventListener<this, TMode>, capture: boolean ): void;};
Add an event listener.
Parameter type
The event type.
Parameter callback
The event listener.
Parameter options
Options.
Add an event listener.
Parameter type
The event type.
Parameter callback
The event listener.
Parameter capture
The capture flag.
Deprecated
Use
{capture: boolean}
object instead of a boolean value.
method dispatchEvent
dispatchEvent: { <T extends string & keyof TEventMap>( event: EventTarget.EventData<TEventMap, TMode, T> ): boolean; (event: EventTarget.FallbackEvent<TMode>): boolean;};
Dispatch an event.
Parameter event
The
Event
object to dispatch.
method removeEventListener
removeEventListener: { <T extends string & keyof TEventMap>( type: T, callback?: EventTarget.EventListener<this, TEventMap[T]> | null, options?: EventTarget.Options ): void; ( type: string, callback?: EventTarget.FallbackEventListener<this, TMode>, options?: EventTarget.Options ): void; <T extends string & keyof TEventMap>( type: T, callback: EventTarget.EventListener<this, TEventMap[T]>, capture: boolean ): void; ( type: string, callback: EventTarget.FallbackEventListener<this, TMode>, capture: boolean ): void;};
Remove an added event listener.
Parameter type
The event type.
Parameter callback
The event listener.
Parameter options
Options.
Remove an added event listener.
Parameter type
The event type.
Parameter callback
The event listener.
Parameter capture
The capture flag.
Deprecated
Use
{capture: boolean}
object instead of a boolean value.
Namespaces
namespace defineCustomEventTarget
namespace defineCustomEventTarget {}
type CustomEventTarget
type CustomEventTarget< TEventMap extends Record<string, Event>, TMode extends 'standard' | 'strict'> = EventTarget<TEventMap, TMode> & defineEventAttribute.EventAttributes<any, TEventMap>;
The interface of CustomEventTarget.
type CustomEventTargetConstructor
type CustomEventTargetConstructor< TEventMap extends Record<string, Event>, TMode extends 'standard' | 'strict'> = { /** * Create a new instance. */ new (): CustomEventTarget<TEventMap, TMode>; /** * prototype object. */ prototype: CustomEventTarget<TEventMap, TMode>;};
The interface of CustomEventTarget constructor.
namespace defineEventAttribute
namespace defineEventAttribute {}
type EventAttributes
type EventAttributes< TEventTarget extends EventTarget<any, any>, TEventMap extends Record<string, Event>> = { [P in string & keyof TEventMap as `on${P}`]: EventTarget.CallbackFunction< TEventTarget, TEventMap[P] > | null;};
Definition of event attributes.
namespace Event
namespace Event {}
interface EventInit
interface EventInit {}
The options of the
Event
constructor.See Also
https://dom.spec.whatwg.org/#dictdef-eventinit
property bubbles
bubbles?: boolean;
property cancelable
cancelable?: boolean;
property composed
composed?: boolean;
namespace EventTarget
namespace EventTarget {}
interface AbortSignal
interface AbortSignal extends EventTarget<{ abort: Event; }> {}
The abort signal.
See Also
https://dom.spec.whatwg.org/#abortsignal
interface AddOptions
interface AddOptions extends Options {}
The options for the
addEventListener
methods.See Also
https://dom.spec.whatwg.org/#dictdef-addeventlisteneroptions
interface CallbackFunction
interface CallbackFunction< TEventTarget extends EventTarget<any, any>, TEvent extends Event> {}
The event listener function.
call signature
(this: TEventTarget, event: TEvent): void;
interface CallbackObject
interface CallbackObject<TEvent extends Event> {}
The event listener object.
See Also
https://dom.spec.whatwg.org/#callbackdef-eventlistener
method handleEvent
handleEvent: (event: TEvent) => void;
interface Options
interface Options {}
The common options for both
addEventListener
andremoveEventListener
methods.See Also
https://dom.spec.whatwg.org/#dictdef-eventlisteneroptions
property capture
capture?: boolean;
type EventData
type EventData< TEventMap extends Record<string, Event>, TMode extends 'standard' | 'strict', TEventType extends string> = TMode extends 'strict' ? IsValidEventMap<TEventMap> extends true ? ExplicitType<TEventType> & Omit<TEventMap[TEventType], keyof Event> & Partial<Omit<Event, 'type'>> : never : never;
The event data to dispatch in strict mode.
type EventListener
type EventListener< TEventTarget extends EventTarget<any, any>, TEvent extends Event> = CallbackFunction<TEventTarget, TEvent> | CallbackObject<TEvent>;
The event listener.
type ExplicitType
type ExplicitType<T extends string> = string extends T ? never : { readonly type: T; };
Define explicit
type
property ifT
is a string literal. Otherwise, never.
type FallbackEvent
type FallbackEvent<TMode extends 'standard' | 'strict'> = TMode extends 'standard' ? Event : never;
The event type in standard mode. Otherwise, never.
type FallbackEventListener
type FallbackEventListener< TEventTarget extends EventTarget<any, any>, TMode extends 'standard' | 'strict'> = TMode extends 'standard' ? EventListener<TEventTarget, Event> | null | undefined : never;
The event listener type in standard mode. Otherwise, never.
type IsValidEventMap
type IsValidEventMap<T> = string extends keyof T ? false : true;
Check if given event map is valid. It's valid if the keys of the event map are narrower than
string
.
namespace setErrorHandler
namespace setErrorHandler {}
type ErrorHandler
type ErrorHandler = (error: Error) => void;
The error handler.
Parameter error
The thrown error object.
namespace setWarningHandler
namespace setWarningHandler {}
interface Warning
interface Warning {}
The warning information.
type WarningHandler
type WarningHandler = (warning: Warning) => void;
The warning handler.
Parameter warning
The warning.
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (45)
- @babel/core
- @babel/plugin-transform-runtime
- @babel/preset-env
- @mysticatea/eslint-plugin
- @mysticatea/spy
- @mysticatea/tools
- @rollup/plugin-babel
- @rollup/plugin-typescript
- @types/istanbul-lib-coverage
- @types/istanbul-lib-report
- @types/istanbul-lib-source-maps
- @types/istanbul-reports
- @types/mocha
- @types/rimraf
- assert
- babel-loader
- babel-plugin-istanbul
- buffer
- chalk
- codecov
- cpx
- dts-bundle-generator
- eslint
- istanbul-lib-coverage
- istanbul-lib-report
- istanbul-lib-source-maps
- istanbul-reports
- mocha
- npm-run-all
- path-browserify
- playwright
- prettier
- process
- rimraf
- rollup
- rollup-plugin-terser
- rollup-watch
- stream-browserify
- ts-loader
- ts-node
- tslib
- typescript
- url
- util
- webpack
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/event-target-shim
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/event-target-shim)
- HTML<a href="https://www.jsdocs.io/package/event-target-shim"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5146 ms. - Missing or incorrect documentation? Open an issue for this package.