Skip to content

Commit

Permalink
Update: Add types
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Jul 4, 2024
1 parent 9af77c6 commit 0042275
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
16 changes: 11 additions & 5 deletions Resources/Private/Assets/EventDispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
function eventDispatcher(eventName, options, element = document) {
type Element = HTMLElement | Document | DocumentFragment | HTMLTemplateElement | Window;

function eventDispatcher(eventName: string, options: any, element: Element = document) {
if (options?.detail === undefined) {
defaultEvent(eventName, options, element);
return;
}
customEvent(eventName, options.detail, options, element);
}

function defaultEvent(eventName, { bubbles = true, cancelable = true, composed = true } = {}, element = document) {
function defaultEvent(
eventName: string,
{ bubbles = true, cancelable = true, composed = true } = {},
element: Element = document,
) {
element.dispatchEvent(new Event(eventName, { bubbles, cancelable, composed }));
}

function customEvent(
eventName,
detail,
eventName: string,
detail: any,
{ bubbles = true, cancelable = true, composed = true } = {},
element = document,
element: Element = document,
) {
element.dispatchEvent(new CustomEvent(eventName, { detail, bubbles, cancelable, composed }));
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Assets/EventListener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function eventListener(name, callback, once = true) {
function eventListener(name: string, callback: Function, once = true) {
if (typeof name !== 'string' || typeof callback !== 'function') {
throw new Error('eventListener: name must be a string and callback must be a function');
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Modules/EventDispatcher.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/Public/Modules/EventListener.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Resources/Public/Modules/Loader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0042275

Please sign in to comment.