@slickgrid-universal/event-pub-sub
Advanced tools
Comparing version 5.10.2 to 5.12.0
@@ -69,6 +69,6 @@ "use strict"; | ||
case eventNamingStyle_enum_js_1.EventNamingStyle.camelCase: | ||
outputEventName = (eventNamePrefix !== '') ? `${eventNamePrefix}${(0, utils_1.titleCase)(inputEventName)}` : inputEventName; | ||
outputEventName = eventNamePrefix !== '' ? `${eventNamePrefix}${(0, utils_1.titleCase)(inputEventName)}` : inputEventName; | ||
break; | ||
case eventNamingStyle_enum_js_1.EventNamingStyle.kebabCase: | ||
outputEventName = (eventNamePrefix !== '') ? `${eventNamePrefix}-${(0, utils_1.toKebabCase)(inputEventName)}` : (0, utils_1.toKebabCase)(inputEventName); | ||
outputEventName = eventNamePrefix !== '' ? `${eventNamePrefix}-${(0, utils_1.toKebabCase)(inputEventName)}` : (0, utils_1.toKebabCase)(inputEventName); | ||
break; | ||
@@ -96,3 +96,3 @@ case eventNamingStyle_enum_js_1.EventNamingStyle.lowerCase: | ||
if (delay) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
window.clearTimeout(this._timer); | ||
@@ -115,3 +115,3 @@ this._timer = window.setTimeout(() => resolve(this.dispatchCustomEvent(eventNameByConvention, data, true, true, externalizeEventCallback)), delay); | ||
const subscriptions = []; | ||
eventNames.forEach(eventName => { | ||
eventNames.forEach((eventName) => { | ||
const eventNameByConvention = this.getEventNameByNamingConvention(eventName, ''); | ||
@@ -126,3 +126,3 @@ // the event listener will return the data in the "event.detail", so we need to return its content to the final callback | ||
return { | ||
unsubscribe: () => subscriptions.forEach(unsub => unsub()) | ||
unsubscribe: () => subscriptions.forEach((unsub) => unsub()), | ||
}; | ||
@@ -143,3 +143,3 @@ } | ||
return { | ||
unsubscribe: () => this.unsubscribe(eventNameByConvention, listener) | ||
unsubscribe: () => this.unsubscribe(eventNameByConvention, listener), | ||
}; | ||
@@ -187,3 +187,3 @@ } | ||
removeSubscribedEventWhenFound(eventName, listener) { | ||
const eventIdx = this._subscribedEvents.findIndex(evt => evt.name === eventName && evt.listener === listener); | ||
const eventIdx = this._subscribedEvents.findIndex((evt) => evt.name === eventName && evt.listener === listener); | ||
if (eventIdx >= 0) { | ||
@@ -190,0 +190,0 @@ this._subscribedEvents.splice(eventIdx, 1); |
import { titleCase, toKebabCase } from '@slickgrid-universal/utils'; | ||
import {} from './types/basePubSubService.interface.js'; | ||
import { EventNamingStyle } from './types/eventNamingStyle.enum.js'; | ||
import {} from './types/eventSubscription.interface.js'; | ||
export class EventPubSubService { | ||
@@ -66,6 +68,6 @@ get elementSource() { | ||
case EventNamingStyle.camelCase: | ||
outputEventName = (eventNamePrefix !== '') ? `${eventNamePrefix}${titleCase(inputEventName)}` : inputEventName; | ||
outputEventName = eventNamePrefix !== '' ? `${eventNamePrefix}${titleCase(inputEventName)}` : inputEventName; | ||
break; | ||
case EventNamingStyle.kebabCase: | ||
outputEventName = (eventNamePrefix !== '') ? `${eventNamePrefix}-${toKebabCase(inputEventName)}` : toKebabCase(inputEventName); | ||
outputEventName = eventNamePrefix !== '' ? `${eventNamePrefix}-${toKebabCase(inputEventName)}` : toKebabCase(inputEventName); | ||
break; | ||
@@ -93,3 +95,3 @@ case EventNamingStyle.lowerCase: | ||
if (delay) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
window.clearTimeout(this._timer); | ||
@@ -112,3 +114,3 @@ this._timer = window.setTimeout(() => resolve(this.dispatchCustomEvent(eventNameByConvention, data, true, true, externalizeEventCallback)), delay); | ||
const subscriptions = []; | ||
eventNames.forEach(eventName => { | ||
eventNames.forEach((eventName) => { | ||
const eventNameByConvention = this.getEventNameByNamingConvention(eventName, ''); | ||
@@ -123,3 +125,3 @@ // the event listener will return the data in the "event.detail", so we need to return its content to the final callback | ||
return { | ||
unsubscribe: () => subscriptions.forEach(unsub => unsub()) | ||
unsubscribe: () => subscriptions.forEach((unsub) => unsub()), | ||
}; | ||
@@ -140,3 +142,3 @@ } | ||
return { | ||
unsubscribe: () => this.unsubscribe(eventNameByConvention, listener) | ||
unsubscribe: () => this.unsubscribe(eventNameByConvention, listener), | ||
}; | ||
@@ -184,3 +186,3 @@ } | ||
removeSubscribedEventWhenFound(eventName, listener) { | ||
const eventIdx = this._subscribedEvents.findIndex(evt => evt.name === eventName && evt.listener === listener); | ||
const eventIdx = this._subscribedEvents.findIndex((evt) => evt.name === eventName && evt.listener === listener); | ||
if (eventIdx >= 0) { | ||
@@ -187,0 +189,0 @@ this._subscribedEvents.splice(eventIdx, 1); |
@@ -27,6 +27,6 @@ import type { EventSubscription } from './eventSubscription.interface.js'; | ||
/** | ||
* Unsubscribes a message name | ||
* @param event The event name | ||
* @return possibly a Subscription | ||
*/ | ||
* Unsubscribes a message name | ||
* @param event The event name | ||
* @return possibly a Subscription | ||
*/ | ||
unsubscribe(_eventName: string, _callback: (event: CustomEventInit) => void): void; | ||
@@ -33,0 +33,0 @@ /** Unsubscribes all subscriptions that currently exists */ |
{ | ||
"name": "@slickgrid-universal/event-pub-sub", | ||
"version": "5.10.2", | ||
"version": "5.12.0", | ||
"description": "Simple Vanilla Implementation of an Event PubSub Service to do simply publish/subscribe inter-communication while optionally providing data in the event", | ||
@@ -41,5 +41,5 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@slickgrid-universal/utils": "~5.10.2" | ||
"@slickgrid-universal/utils": "~5.12.0" | ||
}, | ||
"gitHead": "61dcfac0074bedede5bed92faa49c2d42d551f4c" | ||
"gitHead": "d7e892ebc1727d7c83cc1e5cc80db8302eef4f63" | ||
} |
import { titleCase, toKebabCase } from '@slickgrid-universal/utils'; | ||
import { type BasePubSubService } from './types/basePubSubService.interface.js'; | ||
import { EventNamingStyle } from './types/eventNamingStyle.enum.js'; | ||
import { type EventSubscription, type Subscription, } from './types/eventSubscription.interface.js'; | ||
import { type EventSubscription, type Subscription } from './types/eventSubscription.interface.js'; | ||
@@ -56,3 +56,9 @@ export interface PubSubEvent<T = any> { | ||
*/ | ||
dispatchCustomEvent<T = any>(eventName: string, data?: T, isBubbling = true, isCancelable = true, externalizeEventCallback?: (e: Event) => void): boolean { | ||
dispatchCustomEvent<T = any>( | ||
eventName: string, | ||
data?: T, | ||
isBubbling = true, | ||
isCancelable = true, | ||
externalizeEventCallback?: (e: Event) => void | ||
): boolean { | ||
const eventInit: CustomEventInit<T> = { bubbles: isBubbling, cancelable: isCancelable }; | ||
@@ -86,6 +92,6 @@ if (data) { | ||
case EventNamingStyle.camelCase: | ||
outputEventName = (eventNamePrefix !== '') ? `${eventNamePrefix}${titleCase(inputEventName)}` : inputEventName; | ||
outputEventName = eventNamePrefix !== '' ? `${eventNamePrefix}${titleCase(inputEventName)}` : inputEventName; | ||
break; | ||
case EventNamingStyle.kebabCase: | ||
outputEventName = (eventNamePrefix !== '') ? `${eventNamePrefix}-${toKebabCase(inputEventName)}` : toKebabCase(inputEventName); | ||
outputEventName = eventNamePrefix !== '' ? `${eventNamePrefix}-${toKebabCase(inputEventName)}` : toKebabCase(inputEventName); | ||
break; | ||
@@ -115,5 +121,8 @@ case EventNamingStyle.lowerCase: | ||
if (delay) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
window.clearTimeout(this._timer); | ||
this._timer = window.setTimeout(() => resolve(this.dispatchCustomEvent<T>(eventNameByConvention, data, true, true, externalizeEventCallback)), delay); | ||
this._timer = window.setTimeout( | ||
() => resolve(this.dispatchCustomEvent<T>(eventNameByConvention, data, true, true, externalizeEventCallback)), | ||
delay | ||
); | ||
}); | ||
@@ -135,3 +144,3 @@ } else { | ||
eventNames.forEach(eventName => { | ||
eventNames.forEach((eventName) => { | ||
const eventNameByConvention = this.getEventNameByNamingConvention(eventName, ''); | ||
@@ -148,3 +157,3 @@ | ||
return { | ||
unsubscribe: () => subscriptions.forEach(unsub => unsub()) | ||
unsubscribe: () => subscriptions.forEach((unsub) => unsub()), | ||
}; | ||
@@ -167,3 +176,3 @@ } | ||
return { | ||
unsubscribe: () => this.unsubscribe(eventNameByConvention, listener as never) | ||
unsubscribe: () => this.unsubscribe(eventNameByConvention, listener as never), | ||
}; | ||
@@ -213,3 +222,3 @@ } | ||
protected removeSubscribedEventWhenFound<T>(eventName: string, listener: (event: T | CustomEventInit<T>) => void): void { | ||
const eventIdx = this._subscribedEvents.findIndex(evt => evt.name === eventName && evt.listener === listener); | ||
const eventIdx = this._subscribedEvents.findIndex((evt) => evt.name === eventName && evt.listener === listener); | ||
if (eventIdx >= 0) { | ||
@@ -216,0 +225,0 @@ this._subscribedEvents.splice(eventIdx, 1); |
export * from './eventPubSub.service.js'; | ||
export type * from './types/basePubSubService.interface.js'; | ||
export * from './types/eventNamingStyle.enum.js'; | ||
export type * from './types/eventSubscription.interface.js'; | ||
export type * from './types/eventSubscription.interface.js'; |
@@ -11,3 +11,8 @@ import type { EventSubscription } from './eventSubscription.interface.js'; | ||
*/ | ||
publish<T = any>(_eventName: string | any, _data?: T, _delay?: number, externalizeEventCallback?: (e: Event) => void): void | boolean | Promise<boolean>; | ||
publish<T = any>( | ||
_eventName: string | any, | ||
_data?: T, | ||
_delay?: number, | ||
externalizeEventCallback?: (e: Event) => void | ||
): void | boolean | Promise<boolean>; | ||
@@ -32,6 +37,6 @@ /** | ||
/** | ||
* Unsubscribes a message name | ||
* @param event The event name | ||
* @return possibly a Subscription | ||
*/ | ||
* Unsubscribes a message name | ||
* @param event The event name | ||
* @return possibly a Subscription | ||
*/ | ||
unsubscribe(_eventName: string, _callback: (event: CustomEventInit) => void): void; | ||
@@ -38,0 +43,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
101969
3637
826
0
+ Added@slickgrid-universal/utils@5.12.0(transitive)
- Removed@slickgrid-universal/utils@5.10.2(transitive)