- Description:
An Event dispatcher used to dispatch Native JS CustomEvent objects with custom default properties.
- Source:
- Since:
- 4.0
- Copyright:
- 2021 Andrew Nicols
- 2021 Andrew Nicols
- License:
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
An Event dispatcher used to dispatch Native JS CustomEvent objects with custom default properties.
Methods
(inner) dispatchEvent(eventName, detail, container, options) → {CustomEvent}
- Description:
Dispatch an event as a CustomEvent on the specified container. By default events are bubbled, and cancelable.
The eventName should typically by sourced using a constant. See the supplied examples.
Note: This function uses native events. Any additional details are passed to the function in event.detail.
This function mimics the behaviour of EventTarget.dispatchEvent but bubbles by default.
- Source:
Example
// mod/example/amd/src/events.js
import {dispatchEvent} from 'core/event_dispatcher';
export const eventTypes = {
exampleDataDisplayed: 'mod_example/exampleDataDisplayed',
};
export const notifyExampleDisplayed = someArgument => dispatchEvent(eventTypes.exampleDataDisplayed, {
someArgument,
}, document, {
cancelable: false,
});
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
eventName |
String | The name of the event |
||||||||||||
detail |
Object | Any additional details to pass into the eveent |
||||||||||||
container |
HTMLElement | The point at which to dispatch the event |
||||||||||||
options |
Object |
Properties
|
Returns:
- Type
- CustomEvent