@ahoo-wang/fetcher-eventbus 3.1.8 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abstractTypedEventBus.d.ts.map +1 -1
- package/dist/eventBus.d.ts.map +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/parallelTypedEventBus.d.ts.map +1 -1
- package/dist/serialTypedEventBus.d.ts.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstractTypedEventBus.d.ts","sourceRoot":"","sources":["../src/abstractTypedEventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAElD,8BAAsB,qBAAqB,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"abstractTypedEventBus.d.ts","sourceRoot":"","sources":["../src/abstractTypedEventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAElD,8BAAsB,qBAAqB,CAAC,KAAK,CAC/C,YAAW,aAAa,CAAC,KAAK,CAAC;IAE/B,SAAS,CAAC,aAAa,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAM;IACpD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB;;OAEG;IACH,IAAI,QAAQ,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE,CAEpC;IAED,OAAO;cAIS,WAAW,CACzB,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,EAC5B,KAAK,EAAE,KAAK,GACX,OAAO,CAAC,IAAI,CAAC;IAQhB,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1C,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAEnC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,OAAO;CACnD"}
|
package/dist/eventBus.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventBus.d.ts","sourceRoot":"","sources":["../src/eventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,SAAS,KAAK,aAAa,CAAC,OAAO,CAAC,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ,CAAC,MAAM,SAAS,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC;IAQjD,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAPjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqD;IAE3E;;;;OAIG;gBAC0B,oBAAoB,EAAE,oBAAoB;
|
|
1
|
+
{"version":3,"file":"eventBus.d.ts","sourceRoot":"","sources":["../src/eventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,SAAS,KAAK,aAAa,CAAC,OAAO,CAAC,CAAC;AAE/E;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ,CAAC,MAAM,SAAS,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC;IAQjD,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAPjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqD;IAE3E;;;;OAIG;gBAC0B,oBAAoB,EAAE,oBAAoB;IAEvE;;;;;;;OAOG;IACH,EAAE,CAAC,GAAG,SAAS,SAAS,EACtB,IAAI,EAAE,GAAG,EACT,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GACjC,OAAO;IASV;;;;;;;OAOG;IACH,GAAG,CAAC,GAAG,SAAS,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO;IAI5D;;;;;;;OAOG;IACH,IAAI,CAAC,GAAG,SAAS,SAAS,EACxB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,GACjB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvB;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/eventBus.ts","../src/abstractTypedEventBus.ts","../src/parallelTypedEventBus.ts","../src/serialTypedEventBus.ts","../src/messengers/broadcastChannelMessenger.ts","../src/messengers/storageMessenger.ts","../src/messengers/crossTabMessenger.ts","../src/broadcastTypedEventBus.ts","../src/nameGenerator.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { TypedEventBus } from './typedEventBus';\n\n/**\n * Supplier function for creating TypedEventBus instances by event type\n */\nexport type TypeEventBusSupplier = (type: EventType) => TypedEventBus<unknown>;\n\n/**\n * Generic event bus that manages multiple event types using lazy-loaded TypedEventBus instances\n *\n * @template Events - A record mapping event types to their event data types\n *\n * @example\n * ```typescript\n * const supplier = (type: EventType) => new SerialTypedEventBus(type);\n * const bus = new EventBus<{ 'user-login': string; 'order-update': number }>(supplier);\n * bus.on('user-login', { name: 'logger', order: 1, handle: (event) => console.log(event) });\n * await bus.emit('user-login', 'john-doe');\n * ```\n */\nexport class EventBus<Events extends Record<EventType, unknown>> {\n private readonly buses: Map<EventType, TypedEventBus<unknown>> = new Map();\n\n /**\n * Creates a generic event bus\n *\n * @param typeEventBusSupplier - Function to create TypedEventBus for specific event types\n */\n constructor(private readonly typeEventBusSupplier: TypeEventBusSupplier) {\n }\n\n /**\n * Adds an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to listen for\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on<Key extends EventType>(\n type: Key,\n handler: EventHandler<Events[Key]>,\n ): boolean {\n let bus = this.buses.get(type);\n if (!bus) {\n bus = this.typeEventBusSupplier(type);\n this.buses.set(type, bus);\n }\n return bus?.on(handler) ?? false;\n }\n\n /**\n * Removes an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type\n * @param name - The name of the event handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off<Key extends EventType>(\n type: Key,\n name: string,\n ): boolean {\n return this.buses.get(type)?.off(name) ?? false;\n }\n\n /**\n * Emits an event for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to emit\n * @param event - The event data\n * @returns Promise if the underlying bus is async, void otherwise\n */\n emit<Key extends EventType>(\n type: Key,\n event: Events[Key],\n ): void | Promise<void> {\n return this.buses.get(type)?.emit(event);\n }\n\n /**\n * Cleans up all managed event buses\n */\n destroy(): void {\n for (const bus of this.buses.values()) {\n bus.destroy();\n }\n this.buses.clear();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\n\nexport abstract class AbstractTypedEventBus<EVENT> implements TypedEventBus<EVENT> {\n protected eventHandlers: EventHandler<EVENT>[] = [];\n abstract type: EventType;\n\n /**\n * Gets a copy of all registered event handlers, sorted by order\n */\n get handlers(): EventHandler<EVENT>[] {\n return [...this.eventHandlers];\n }\n\n destroy() {\n this.eventHandlers = [];\n }\n\n protected async handleEvent(handler: EventHandler<EVENT>, event: EVENT): Promise<void> {\n try {\n handler.handle(event);\n } catch (e) {\n console.warn(`Event handler error for ${handler.name}:`, e);\n }\n }\n\n abstract emit(event: EVENT): Promise<void>;\n\n abstract off(name: string): boolean;\n\n abstract on(handler: EventHandler<EVENT>): boolean;\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Parallel implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers in parallel.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new ParallelTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // Both handlers execute in parallel\n * ```\n */\nexport class ParallelTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n\n /**\n * Creates a parallel typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers in parallel\n *\n * Handlers are executed concurrently. Once-only handlers are removed after all executions complete.\n * Errors in individual handlers are logged but do not affect other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n const promises = this.eventHandlers.map(async handler => {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n });\n await Promise.all(promises);\n if (onceHandlers.length > 0) {\n this.eventHandlers = this.eventHandlers.filter(\n item => !onceHandlers.includes(item),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = original.filter(item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = [...original, handler];\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { toSorted } from '@ahoo-wang/fetcher';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Serial implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers serially in order of priority.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new SerialTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // handler1 executes first, then handler2\n * ```\n */\nexport class SerialTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n\n /**\n * Creates an in-memory typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers serially\n *\n * Handlers are executed in order of their priority. Once-only handlers are removed after execution.\n * Errors in individual handlers are logged but do not stop other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n for (const handler of this.eventHandlers) {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n }\n if (onceHandlers.length > 0) {\n this.eventHandlers = toSorted(\n this.eventHandlers.filter(item => !onceHandlers.includes(item)),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = toSorted(original, item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = toSorted([...original, handler]);\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport class BroadcastChannelMessenger implements CrossTabMessenger {\n private readonly broadcastChannel: BroadcastChannel;\n\n constructor(channelName: string) {\n this.broadcastChannel = new BroadcastChannel(channelName);\n }\n\n postMessage(message: any): void {\n this.broadcastChannel.postMessage(message);\n }\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages, or undefined to remove handler\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.broadcastChannel.onmessage = (event: MessageEvent) => {\n handler(event.data);\n };\n }\n\n /**\n * Close the messenger and clean up resources\n *\n * After calling close(), the messenger cannot be used again.\n */\n close(): void {\n this.broadcastChannel.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport interface StorageMessengerOptions {\n channelName: string;\n /** Storage instance to use. Defaults to localStorage */\n storage?: Storage;\n ttl?: number;\n cleanupInterval?: number;\n}\n\nexport interface StorageMessage {\n data: any;\n timestamp: number;\n}\n\nconst DEFAULT_TTL = 1000;\nconst DEFAULT_CLEANUP_INTERVAL = 60000;\n\nexport class StorageMessenger implements CrossTabMessenger {\n private readonly channelName: string;\n private readonly storage: Storage;\n private messageHandler?: CrossTabMessageHandler;\n private readonly messageKeyPrefix: string;\n private readonly ttl: number;\n private readonly cleanupInterval: number;\n private cleanupTimer?: number;\n private readonly storageEventHandler = (event: StorageEvent) => {\n if (\n event.storageArea !== this.storage ||\n !event.key?.startsWith(this.messageKeyPrefix) ||\n !event.newValue\n ) {\n return;\n }\n try {\n const storageMessage = JSON.parse(event.newValue) as StorageMessage;\n this.messageHandler?.(storageMessage.data);\n } catch (error) {\n console.warn('Failed to parse storage message:', error);\n }\n };\n\n constructor(options: StorageMessengerOptions) {\n this.channelName = options.channelName;\n this.storage = options.storage ?? localStorage;\n this.messageKeyPrefix = `_storage_msg_${this.channelName}`;\n this.ttl = options.ttl ?? DEFAULT_TTL;\n this.cleanupInterval = options.cleanupInterval ?? DEFAULT_CLEANUP_INTERVAL;\n this.cleanupTimer = window.setInterval(\n () => this.cleanup(),\n this.cleanupInterval,\n );\n window.addEventListener('storage', this.storageEventHandler);\n }\n\n private generateMessageKey(): string {\n return `${this.messageKeyPrefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n /**\n * Send a message to other tabs/windows via localStorage\n */\n postMessage(message: any): void {\n const key = this.generateMessageKey();\n const storageMessage: StorageMessage = {\n data: message,\n timestamp: Date.now(),\n };\n this.storage.setItem(key, JSON.stringify(storageMessage));\n // Delay removal to ensure all listeners have processed the event\n setTimeout(() => this.storage.removeItem(key), this.ttl);\n }\n\n /**\n * Set the message handler for incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.messageHandler = handler;\n }\n\n /**\n * Clean up expired messages from storage\n */\n private cleanup(): void {\n const now = Date.now();\n const keysToRemove: string[] = [];\n for (let i = 0; i < this.storage.length; i++) {\n const key = this.storage.key(i);\n if (key?.startsWith(this.messageKeyPrefix)) {\n try {\n const value = this.storage.getItem(key);\n if (value) {\n const message: StorageMessage = JSON.parse(value);\n if (now > message.timestamp + this.ttl) {\n keysToRemove.push(key);\n }\n }\n } catch {\n // Invalid data, remove it\n keysToRemove.push(key);\n }\n }\n }\n keysToRemove.forEach(key => this.storage.removeItem(key));\n }\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void {\n if (this.cleanupTimer) {\n clearInterval(this.cleanupTimer);\n }\n window.removeEventListener('storage', this.storageEventHandler);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BroadcastChannelMessenger } from './broadcastChannelMessenger';\nimport { StorageMessenger } from './storageMessenger';\n\nexport type CrossTabMessageHandler = (message: any) => void;\n\n/**\n * Interface for cross-tab communication messengers\n *\n * Provides a unified API for different cross-tab communication mechanisms\n * like BroadcastChannel, StorageEvent, SharedWorker, etc.\n */\nexport interface CrossTabMessenger {\n /**\n * Send a message to other tabs/windows\n *\n * @param message - The data to send\n */\n postMessage(message: any): void;\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler);\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void;\n}\n\nexport function isBroadcastChannelSupported(): boolean {\n return (\n typeof BroadcastChannel !== 'undefined' &&\n typeof BroadcastChannel.prototype?.postMessage === 'function'\n );\n}\n\nexport function isStorageEventSupported(): boolean {\n return (\n typeof StorageEvent !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window.addEventListener === 'function' &&\n (typeof localStorage !== 'undefined' ||\n typeof sessionStorage !== 'undefined')\n );\n}\n\nexport function createCrossTabMessenger(\n channelName: string,\n): CrossTabMessenger | undefined {\n if (isBroadcastChannelSupported()) {\n return new BroadcastChannelMessenger(channelName);\n }\n\n if (isStorageEventSupported()) {\n return new StorageMessenger({ channelName });\n }\n\n return undefined;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\nimport { createCrossTabMessenger, CrossTabMessenger } from './messengers';\n\n/**\n * Configuration options for BroadcastTypedEventBus\n *\n * @template EVENT - The event type this bus will handle\n */\nexport interface BroadcastTypedEventBusOptions<EVENT> {\n /**\n * The underlying event bus that handles local event processing and storage.\n * This bus manages event handlers and local event emission.\n */\n delegate: TypedEventBus<EVENT>;\n\n /**\n * Optional messenger for cross-tab/window communication.\n * If not provided, a default BroadcastChannel-based messenger will be created\n * using the pattern `_broadcast_:{type}`. Must be a valid CrossTabMessenger\n * implementation when provided.\n */\n messenger?: CrossTabMessenger;\n}\n\n/**\n * Broadcast event bus that enables cross-tab/window communication\n *\n * This class extends a local TypedEventBus with cross-context broadcasting capabilities.\n * When events are emitted, they are first processed locally by the delegate bus, then\n * broadcasted to other browser contexts (tabs, windows, etc.) through the provided messenger.\n *\n * Incoming broadcast messages from other contexts are automatically forwarded to the\n * local delegate bus for processing by registered event handlers.\n *\n * @template EVENT - The event type this bus handles (must be serializable for cross-context transport)\n *\n * @example Basic usage with default messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create broadcast event bus with default messenger\n * const bus = new BroadcastTypedEventBus({\n * delegate\n * // messenger will be auto-created as '_broadcast_:user-events'\n * });\n *\n * // Register event handler\n * bus.on({\n * name: 'user-login',\n * order: 1,\n * handle: (username: string) => console.log(`User ${username} logged in`)\n * });\n *\n * // Emit event (will be processed locally and broadcasted to other tabs)\n * await bus.emit('john-doe');\n * ```\n *\n * @example Using custom messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { createCrossTabMessenger } from './messengers';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create custom cross-tab messenger\n * const messenger = createCrossTabMessenger('my-custom-channel');\n *\n * // Create broadcast event bus\n * const bus = new BroadcastTypedEventBus({\n * delegate,\n * messenger\n * });\n *\n * // Register event handler and emit events...\n * ```\n *\n * @example Using custom messenger implementation\n * ```typescript\n * class CustomMessenger implements CrossTabMessenger {\n * // ... implementation\n * }\n *\n * const customMessenger = new CustomMessenger();\n * const bus = new BroadcastTypedEventBus({\n * delegate: new SerialTypedEventBus('events'),\n * messenger: customMessenger\n * });\n * ```\n */\nexport class BroadcastTypedEventBus<EVENT> implements TypedEventBus<EVENT> {\n public readonly type: EventType;\n private readonly delegate: TypedEventBus<EVENT>;\n private messenger: CrossTabMessenger;\n\n /**\n * Creates a new broadcast event bus with cross-context communication\n *\n * @param options - Configuration object containing delegate bus and optional messenger\n * @throws {Error} If messenger creation fails when no messenger is provided\n */\n constructor(options: BroadcastTypedEventBusOptions<EVENT>) {\n this.delegate = options.delegate;\n this.type = this.delegate.type;\n const messenger =\n options.messenger ?? createCrossTabMessenger(`_broadcast_:${this.type}`);\n if (!messenger) {\n throw new Error('Messenger setup failed');\n }\n this.messenger = messenger;\n this.messenger.onmessage = async (event: EVENT) => {\n await this.delegate.emit(event);\n };\n }\n\n /**\n * Returns a copy of all currently registered event handlers\n *\n * This getter delegates to the underlying event bus and returns the current\n * list of handlers that will process incoming events.\n *\n * @returns Array of event handlers registered with this bus\n */\n get handlers(): EventHandler<EVENT>[] {\n return this.delegate.handlers;\n }\n\n /**\n * Emits an event locally and broadcasts it to other browser contexts\n *\n * This method first processes the event through the local delegate bus,\n * allowing all registered local handlers to process it. Then, if successful,\n * the event is broadcasted to other tabs/windows through the messenger.\n *\n * Note: If broadcasting fails (e.g., due to messenger errors), the local\n * emission is still completed and a warning is logged to console.\n *\n * @param event - The event data to emit and broadcast\n * @returns Promise that resolves when local processing is complete\n * @throws Propagates any errors from local event processing\n */\n async emit(event: EVENT): Promise<void> {\n await this.delegate.emit(event);\n this.messenger.postMessage(event);\n }\n\n /**\n * Removes an event handler by its registered name\n *\n * This method delegates to the underlying event bus to remove the specified\n * handler. The handler will no longer receive events emitted to this bus.\n *\n * @param name - The unique name of the handler to remove\n * @returns true if a handler with the given name was found and removed, false otherwise\n */\n off(name: string): boolean {\n return this.delegate.off(name);\n }\n\n /**\n * Registers a new event handler with this bus\n *\n * The handler will receive all events emitted to this bus, both locally\n * generated and received from other browser contexts via broadcasting.\n *\n * @param handler - The event handler configuration to register\n * @returns true if the handler was successfully added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n return this.delegate.on(handler);\n }\n\n /**\n * Cleans up resources and stops cross-context communication\n *\n * This method closes the messenger connection, preventing further\n * cross-tab communication. Local event handling continues to work\n * through the delegate bus. After calling destroy(), the bus should\n * not be used for broadcasting operations.\n *\n * Note: This does not remove event handlers or affect local event processing.\n */\n destroy(): void {\n this.messenger.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Interface for generating unique names with a prefix\n */\nexport interface NameGenerator {\n generate(prefix: string): string;\n}\n\n/**\n * Default implementation of NameGenerator that generates names with incrementing counters\n */\nexport class DefaultNameGenerator implements NameGenerator {\n private namingCounter: number = 0;\n\n /**\n * Generates a unique name by appending an incrementing counter to the prefix\n * @param prefix - The prefix for the generated name\n * @returns The generated unique name\n */\n generate(prefix: string): string {\n this.namingCounter++;\n return `${prefix}_${this.namingCounter}`;\n }\n}\n\n/**\n * Default instance of NameGenerator\n */\nexport const nameGenerator = new DefaultNameGenerator();\n"],"names":["EventBus","typeEventBusSupplier","type","handler","bus","name","event","AbstractTypedEventBus","e","ParallelTypedEventBus","onceHandlers","promises","item","original","SerialTypedEventBus","toSorted","BroadcastChannelMessenger","channelName","message","DEFAULT_TTL","DEFAULT_CLEANUP_INTERVAL","StorageMessenger","options","storageMessage","error","key","now","keysToRemove","i","value","isBroadcastChannelSupported","isStorageEventSupported","createCrossTabMessenger","BroadcastTypedEventBus","messenger","DefaultNameGenerator","prefix","nameGenerator"],"mappings":";AAkCO,MAAMA,EAAoD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/D,YAA6BC,GAA4C;AAA5C,SAAA,uBAAAA,GAP7B,KAAiB,4BAAoD,IAAA;AAAA,EAQrE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,GACEC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CAAK;AAAA,IAChC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,IAAI,WAAkC;AACpC,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,KAAKA,GAA6B;AACtC,UAAM,KAAK,SAAS,KAAKA,CAAK,GAC9B,KAAK,UAAU,YAAYA,CAAK;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,IAAID,GAAuB;AACzB,WAAO,KAAK,SAAS,IAAIA,CAAI;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,GAAGF,GAAuC;AACxC,WAAO,KAAK,SAAS,GAAGA,CAAO;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,UAAgB;AACd,SAAK,UAAU,MAAA;AAAA,EACjB;AACF;ACrLO,MAAMgC,EAA8C;AAAA,EAApD,cAAA;AACL,SAAQ,gBAAwB;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhC,SAASC,GAAwB;AAC/B,gBAAK,iBACE,GAAGA,CAAM,IAAI,KAAK,aAAa;AAAA,EACxC;AACF;AAKO,MAAMC,IAAgB,IAAIF,EAAA;"}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/eventBus.ts","../src/abstractTypedEventBus.ts","../src/parallelTypedEventBus.ts","../src/serialTypedEventBus.ts","../src/messengers/broadcastChannelMessenger.ts","../src/messengers/storageMessenger.ts","../src/messengers/crossTabMessenger.ts","../src/broadcastTypedEventBus.ts","../src/nameGenerator.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { TypedEventBus } from './typedEventBus';\n\n/**\n * Supplier function for creating TypedEventBus instances by event type\n */\nexport type TypeEventBusSupplier = (type: EventType) => TypedEventBus<unknown>;\n\n/**\n * Generic event bus that manages multiple event types using lazy-loaded TypedEventBus instances\n *\n * @template Events - A record mapping event types to their event data types\n *\n * @example\n * ```typescript\n * const supplier = (type: EventType) => new SerialTypedEventBus(type);\n * const bus = new EventBus<{ 'user-login': string; 'order-update': number }>(supplier);\n * bus.on('user-login', { name: 'logger', order: 1, handle: (event) => console.log(event) });\n * await bus.emit('user-login', 'john-doe');\n * ```\n */\nexport class EventBus<Events extends Record<EventType, unknown>> {\n private readonly buses: Map<EventType, TypedEventBus<unknown>> = new Map();\n\n /**\n * Creates a generic event bus\n *\n * @param typeEventBusSupplier - Function to create TypedEventBus for specific event types\n */\n constructor(private readonly typeEventBusSupplier: TypeEventBusSupplier) {}\n\n /**\n * Adds an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to listen for\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on<Key extends EventType>(\n type: Key,\n handler: EventHandler<Events[Key]>,\n ): boolean {\n let bus = this.buses.get(type);\n if (!bus) {\n bus = this.typeEventBusSupplier(type);\n this.buses.set(type, bus);\n }\n return bus?.on(handler) ?? false;\n }\n\n /**\n * Removes an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type\n * @param name - The name of the event handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off<Key extends EventType>(type: Key, name: string): boolean {\n return this.buses.get(type)?.off(name) ?? false;\n }\n\n /**\n * Emits an event for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to emit\n * @param event - The event data\n * @returns Promise if the underlying bus is async, void otherwise\n */\n emit<Key extends EventType>(\n type: Key,\n event: Events[Key],\n ): void | Promise<void> {\n return this.buses.get(type)?.emit(event);\n }\n\n /**\n * Cleans up all managed event buses\n */\n destroy(): void {\n for (const bus of this.buses.values()) {\n bus.destroy();\n }\n this.buses.clear();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\n\nexport abstract class AbstractTypedEventBus<EVENT>\n implements TypedEventBus<EVENT>\n{\n protected eventHandlers: EventHandler<EVENT>[] = [];\n abstract type: EventType;\n\n /**\n * Gets a copy of all registered event handlers, sorted by order\n */\n get handlers(): EventHandler<EVENT>[] {\n return [...this.eventHandlers];\n }\n\n destroy() {\n this.eventHandlers = [];\n }\n\n protected async handleEvent(\n handler: EventHandler<EVENT>,\n event: EVENT,\n ): Promise<void> {\n try {\n handler.handle(event);\n } catch (e) {\n console.warn(`Event handler error for ${handler.name}:`, e);\n }\n }\n\n abstract emit(event: EVENT): Promise<void>;\n\n abstract off(name: string): boolean;\n\n abstract on(handler: EventHandler<EVENT>): boolean;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Parallel implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers in parallel.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new ParallelTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // Both handlers execute in parallel\n * ```\n */\nexport class ParallelTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n /**\n * Creates a parallel typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers in parallel\n *\n * Handlers are executed concurrently. Once-only handlers are removed after all executions complete.\n * Errors in individual handlers are logged but do not affect other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n const promises = this.eventHandlers.map(async handler => {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n });\n await Promise.all(promises);\n if (onceHandlers.length > 0) {\n this.eventHandlers = this.eventHandlers.filter(\n item => !onceHandlers.includes(item),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = original.filter(item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = [...original, handler];\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { toSorted } from '@ahoo-wang/fetcher';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Serial implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers serially in order of priority.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new SerialTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // handler1 executes first, then handler2\n * ```\n */\nexport class SerialTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n /**\n * Creates an in-memory typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers serially\n *\n * Handlers are executed in order of their priority. Once-only handlers are removed after execution.\n * Errors in individual handlers are logged but do not stop other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n for (const handler of this.eventHandlers) {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n }\n if (onceHandlers.length > 0) {\n this.eventHandlers = toSorted(\n this.eventHandlers.filter(item => !onceHandlers.includes(item)),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = toSorted(original, item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = toSorted([...original, handler]);\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport class BroadcastChannelMessenger implements CrossTabMessenger {\n private readonly broadcastChannel: BroadcastChannel;\n\n constructor(channelName: string) {\n this.broadcastChannel = new BroadcastChannel(channelName);\n }\n\n postMessage(message: any): void {\n this.broadcastChannel.postMessage(message);\n }\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages, or undefined to remove handler\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.broadcastChannel.onmessage = (event: MessageEvent) => {\n handler(event.data);\n };\n }\n\n /**\n * Close the messenger and clean up resources\n *\n * After calling close(), the messenger cannot be used again.\n */\n close(): void {\n this.broadcastChannel.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport interface StorageMessengerOptions {\n channelName: string;\n /** Storage instance to use. Defaults to localStorage */\n storage?: Storage;\n ttl?: number;\n cleanupInterval?: number;\n}\n\nexport interface StorageMessage {\n data: any;\n timestamp: number;\n}\n\nconst DEFAULT_TTL = 1000;\nconst DEFAULT_CLEANUP_INTERVAL = 60000;\n\nexport class StorageMessenger implements CrossTabMessenger {\n private readonly channelName: string;\n private readonly storage: Storage;\n private messageHandler?: CrossTabMessageHandler;\n private readonly messageKeyPrefix: string;\n private readonly ttl: number;\n private readonly cleanupInterval: number;\n private cleanupTimer?: number;\n private readonly storageEventHandler = (event: StorageEvent) => {\n if (\n event.storageArea !== this.storage ||\n !event.key?.startsWith(this.messageKeyPrefix) ||\n !event.newValue\n ) {\n return;\n }\n try {\n const storageMessage = JSON.parse(event.newValue) as StorageMessage;\n this.messageHandler?.(storageMessage.data);\n } catch (error) {\n console.warn('Failed to parse storage message:', error);\n }\n };\n\n constructor(options: StorageMessengerOptions) {\n this.channelName = options.channelName;\n this.storage = options.storage ?? localStorage;\n this.messageKeyPrefix = `_storage_msg_${this.channelName}`;\n this.ttl = options.ttl ?? DEFAULT_TTL;\n this.cleanupInterval = options.cleanupInterval ?? DEFAULT_CLEANUP_INTERVAL;\n this.cleanupTimer = window.setInterval(\n () => this.cleanup(),\n this.cleanupInterval,\n );\n window.addEventListener('storage', this.storageEventHandler);\n }\n\n private generateMessageKey(): string {\n return `${this.messageKeyPrefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n /**\n * Send a message to other tabs/windows via localStorage\n */\n postMessage(message: any): void {\n const key = this.generateMessageKey();\n const storageMessage: StorageMessage = {\n data: message,\n timestamp: Date.now(),\n };\n this.storage.setItem(key, JSON.stringify(storageMessage));\n // Delay removal to ensure all listeners have processed the event\n setTimeout(() => this.storage.removeItem(key), this.ttl);\n }\n\n /**\n * Set the message handler for incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.messageHandler = handler;\n }\n\n /**\n * Clean up expired messages from storage\n */\n private cleanup(): void {\n const now = Date.now();\n const keysToRemove: string[] = [];\n for (let i = 0; i < this.storage.length; i++) {\n const key = this.storage.key(i);\n if (key?.startsWith(this.messageKeyPrefix)) {\n try {\n const value = this.storage.getItem(key);\n if (value) {\n const message: StorageMessage = JSON.parse(value);\n if (now > message.timestamp + this.ttl) {\n keysToRemove.push(key);\n }\n }\n } catch {\n // Invalid data, remove it\n keysToRemove.push(key);\n }\n }\n }\n keysToRemove.forEach(key => this.storage.removeItem(key));\n }\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void {\n if (this.cleanupTimer) {\n clearInterval(this.cleanupTimer);\n }\n window.removeEventListener('storage', this.storageEventHandler);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BroadcastChannelMessenger } from './broadcastChannelMessenger';\nimport { StorageMessenger } from './storageMessenger';\n\nexport type CrossTabMessageHandler = (message: any) => void;\n\n/**\n * Interface for cross-tab communication messengers\n *\n * Provides a unified API for different cross-tab communication mechanisms\n * like BroadcastChannel, StorageEvent, SharedWorker, etc.\n */\nexport interface CrossTabMessenger {\n /**\n * Send a message to other tabs/windows\n *\n * @param message - The data to send\n */\n postMessage(message: any): void;\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler);\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void;\n}\n\nexport function isBroadcastChannelSupported(): boolean {\n return (\n typeof BroadcastChannel !== 'undefined' &&\n typeof BroadcastChannel.prototype?.postMessage === 'function'\n );\n}\n\nexport function isStorageEventSupported(): boolean {\n return (\n typeof StorageEvent !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window.addEventListener === 'function' &&\n (typeof localStorage !== 'undefined' ||\n typeof sessionStorage !== 'undefined')\n );\n}\n\nexport function createCrossTabMessenger(\n channelName: string,\n): CrossTabMessenger | undefined {\n if (isBroadcastChannelSupported()) {\n return new BroadcastChannelMessenger(channelName);\n }\n\n if (isStorageEventSupported()) {\n return new StorageMessenger({ channelName });\n }\n\n return undefined;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\nimport { createCrossTabMessenger, CrossTabMessenger } from './messengers';\n\n/**\n * Configuration options for BroadcastTypedEventBus\n *\n * @template EVENT - The event type this bus will handle\n */\nexport interface BroadcastTypedEventBusOptions<EVENT> {\n /**\n * The underlying event bus that handles local event processing and storage.\n * This bus manages event handlers and local event emission.\n */\n delegate: TypedEventBus<EVENT>;\n\n /**\n * Optional messenger for cross-tab/window communication.\n * If not provided, a default BroadcastChannel-based messenger will be created\n * using the pattern `_broadcast_:{type}`. Must be a valid CrossTabMessenger\n * implementation when provided.\n */\n messenger?: CrossTabMessenger;\n}\n\n/**\n * Broadcast event bus that enables cross-tab/window communication\n *\n * This class extends a local TypedEventBus with cross-context broadcasting capabilities.\n * When events are emitted, they are first processed locally by the delegate bus, then\n * broadcasted to other browser contexts (tabs, windows, etc.) through the provided messenger.\n *\n * Incoming broadcast messages from other contexts are automatically forwarded to the\n * local delegate bus for processing by registered event handlers.\n *\n * @template EVENT - The event type this bus handles (must be serializable for cross-context transport)\n *\n * @example Basic usage with default messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create broadcast event bus with default messenger\n * const bus = new BroadcastTypedEventBus({\n * delegate\n * // messenger will be auto-created as '_broadcast_:user-events'\n * });\n *\n * // Register event handler\n * bus.on({\n * name: 'user-login',\n * order: 1,\n * handle: (username: string) => console.log(`User ${username} logged in`)\n * });\n *\n * // Emit event (will be processed locally and broadcasted to other tabs)\n * await bus.emit('john-doe');\n * ```\n *\n * @example Using custom messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { createCrossTabMessenger } from './messengers';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create custom cross-tab messenger\n * const messenger = createCrossTabMessenger('my-custom-channel');\n *\n * // Create broadcast event bus\n * const bus = new BroadcastTypedEventBus({\n * delegate,\n * messenger\n * });\n *\n * // Register event handler and emit events...\n * ```\n *\n * @example Using custom messenger implementation\n * ```typescript\n * class CustomMessenger implements CrossTabMessenger {\n * // ... implementation\n * }\n *\n * const customMessenger = new CustomMessenger();\n * const bus = new BroadcastTypedEventBus({\n * delegate: new SerialTypedEventBus('events'),\n * messenger: customMessenger\n * });\n * ```\n */\nexport class BroadcastTypedEventBus<EVENT> implements TypedEventBus<EVENT> {\n public readonly type: EventType;\n private readonly delegate: TypedEventBus<EVENT>;\n private messenger: CrossTabMessenger;\n\n /**\n * Creates a new broadcast event bus with cross-context communication\n *\n * @param options - Configuration object containing delegate bus and optional messenger\n * @throws {Error} If messenger creation fails when no messenger is provided\n */\n constructor(options: BroadcastTypedEventBusOptions<EVENT>) {\n this.delegate = options.delegate;\n this.type = this.delegate.type;\n const messenger =\n options.messenger ?? createCrossTabMessenger(`_broadcast_:${this.type}`);\n if (!messenger) {\n throw new Error('Messenger setup failed');\n }\n this.messenger = messenger;\n this.messenger.onmessage = async (event: EVENT) => {\n await this.delegate.emit(event);\n };\n }\n\n /**\n * Returns a copy of all currently registered event handlers\n *\n * This getter delegates to the underlying event bus and returns the current\n * list of handlers that will process incoming events.\n *\n * @returns Array of event handlers registered with this bus\n */\n get handlers(): EventHandler<EVENT>[] {\n return this.delegate.handlers;\n }\n\n /**\n * Emits an event locally and broadcasts it to other browser contexts\n *\n * This method first processes the event through the local delegate bus,\n * allowing all registered local handlers to process it. Then, if successful,\n * the event is broadcasted to other tabs/windows through the messenger.\n *\n * Note: If broadcasting fails (e.g., due to messenger errors), the local\n * emission is still completed and a warning is logged to console.\n *\n * @param event - The event data to emit and broadcast\n * @returns Promise that resolves when local processing is complete\n * @throws Propagates any errors from local event processing\n */\n async emit(event: EVENT): Promise<void> {\n await this.delegate.emit(event);\n this.messenger.postMessage(event);\n }\n\n /**\n * Removes an event handler by its registered name\n *\n * This method delegates to the underlying event bus to remove the specified\n * handler. The handler will no longer receive events emitted to this bus.\n *\n * @param name - The unique name of the handler to remove\n * @returns true if a handler with the given name was found and removed, false otherwise\n */\n off(name: string): boolean {\n return this.delegate.off(name);\n }\n\n /**\n * Registers a new event handler with this bus\n *\n * The handler will receive all events emitted to this bus, both locally\n * generated and received from other browser contexts via broadcasting.\n *\n * @param handler - The event handler configuration to register\n * @returns true if the handler was successfully added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n return this.delegate.on(handler);\n }\n\n /**\n * Cleans up resources and stops cross-context communication\n *\n * This method closes the messenger connection, preventing further\n * cross-tab communication. Local event handling continues to work\n * through the delegate bus. After calling destroy(), the bus should\n * not be used for broadcasting operations.\n *\n * Note: This does not remove event handlers or affect local event processing.\n */\n destroy(): void {\n this.messenger.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Interface for generating unique names with a prefix\n */\nexport interface NameGenerator {\n generate(prefix: string): string;\n}\n\n/**\n * Default implementation of NameGenerator that generates names with incrementing counters\n */\nexport class DefaultNameGenerator implements NameGenerator {\n private namingCounter: number = 0;\n\n /**\n * Generates a unique name by appending an incrementing counter to the prefix\n * @param prefix - The prefix for the generated name\n * @returns The generated unique name\n */\n generate(prefix: string): string {\n this.namingCounter++;\n return `${prefix}_${this.namingCounter}`;\n }\n}\n\n/**\n * Default instance of NameGenerator\n */\nexport const nameGenerator = new DefaultNameGenerator();\n"],"names":["EventBus","typeEventBusSupplier","type","handler","bus","name","event","AbstractTypedEventBus","e","ParallelTypedEventBus","onceHandlers","promises","item","original","SerialTypedEventBus","toSorted","BroadcastChannelMessenger","channelName","message","DEFAULT_TTL","DEFAULT_CLEANUP_INTERVAL","StorageMessenger","options","storageMessage","error","key","now","keysToRemove","i","value","isBroadcastChannelSupported","isStorageEventSupported","createCrossTabMessenger","BroadcastTypedEventBus","messenger","DefaultNameGenerator","prefix","nameGenerator"],"mappings":";AAkCO,MAAMA,EAAoD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ/D,YAA6BC,GAA4C;AAA5C,SAAA,uBAAAA,GAP7B,KAAiB,4BAAoD,IAAA;AAAA,EAOK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU1E,GACEC,GACAC,GACS;AACT,QAAIC,IAAM,KAAK,MAAM,IAAIF,CAAI;AAC7B,WAAKE,MACHA,IAAM,KAAK,qBAAqBF,CAAI,GACpC,KAAK,MAAM,IAAIA,GAAME,CAAG,IAEnBA,GAAK,GAAGD,CAAO,KAAK;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,IAA2BD,GAAWG,GAAuB;AAC3D,WAAO,KAAK,MAAM,IAAIH,CAAI,GAAG,IAAIG,CAAI,KAAK;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,KACEH,GACAI,GACsB;AACtB,WAAO,KAAK,MAAM,IAAIJ,CAAI,GAAG,KAAKI,CAAK;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKA,UAAgB;AACd,eAAWF,KAAO,KAAK,MAAM,OAAA;AAC3B,MAAAA,EAAI,QAAA;AAEN,SAAK,MAAM,MAAA;AAAA,EACb;AACF;ACpFO,MAAeG,EAEtB;AAAA,EAFO,cAAA;AAGL,SAAU,gBAAuC,CAAA;AAAA,EAAC;AAAA;AAAA;AAAA;AAAA,EAMlD,IAAI,WAAkC;AACpC,WAAO,CAAC,GAAG,KAAK,aAAa;AAAA,EAC/B;AAAA,EAEA,UAAU;AACR,SAAK,gBAAgB,CAAA;AAAA,E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AAK,iBACE,GAAGA,CAAM,IAAI,KAAK,aAAa;AAAA,EACxC;AACF;AAKO,MAAMC,IAAgB,IAAIF,EAAA;"}
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/eventBus.ts","../src/abstractTypedEventBus.ts","../src/parallelTypedEventBus.ts","../src/serialTypedEventBus.ts","../src/messengers/broadcastChannelMessenger.ts","../src/messengers/storageMessenger.ts","../src/messengers/crossTabMessenger.ts","../src/broadcastTypedEventBus.ts","../src/nameGenerator.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { TypedEventBus } from './typedEventBus';\n\n/**\n * Supplier function for creating TypedEventBus instances by event type\n */\nexport type TypeEventBusSupplier = (type: EventType) => TypedEventBus<unknown>;\n\n/**\n * Generic event bus that manages multiple event types using lazy-loaded TypedEventBus instances\n *\n * @template Events - A record mapping event types to their event data types\n *\n * @example\n * ```typescript\n * const supplier = (type: EventType) => new SerialTypedEventBus(type);\n * const bus = new EventBus<{ 'user-login': string; 'order-update': number }>(supplier);\n * bus.on('user-login', { name: 'logger', order: 1, handle: (event) => console.log(event) });\n * await bus.emit('user-login', 'john-doe');\n * ```\n */\nexport class EventBus<Events extends Record<EventType, unknown>> {\n private readonly buses: Map<EventType, TypedEventBus<unknown>> = new Map();\n\n /**\n * Creates a generic event bus\n *\n * @param typeEventBusSupplier - Function to create TypedEventBus for specific event types\n */\n constructor(private readonly typeEventBusSupplier: TypeEventBusSupplier) {\n }\n\n /**\n * Adds an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to listen for\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on<Key extends EventType>(\n type: Key,\n handler: EventHandler<Events[Key]>,\n ): boolean {\n let bus = this.buses.get(type);\n if (!bus) {\n bus = this.typeEventBusSupplier(type);\n this.buses.set(type, bus);\n }\n return bus?.on(handler) ?? false;\n }\n\n /**\n * Removes an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type\n * @param name - The name of the event handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off<Key extends EventType>(\n type: Key,\n name: string,\n ): boolean {\n return this.buses.get(type)?.off(name) ?? false;\n }\n\n /**\n * Emits an event for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to emit\n * @param event - The event data\n * @returns Promise if the underlying bus is async, void otherwise\n */\n emit<Key extends EventType>(\n type: Key,\n event: Events[Key],\n ): void | Promise<void> {\n return this.buses.get(type)?.emit(event);\n }\n\n /**\n * Cleans up all managed event buses\n */\n destroy(): void {\n for (const bus of this.buses.values()) {\n bus.destroy();\n }\n this.buses.clear();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\n\nexport abstract class AbstractTypedEventBus<EVENT> implements TypedEventBus<EVENT> {\n protected eventHandlers: EventHandler<EVENT>[] = [];\n abstract type: EventType;\n\n /**\n * Gets a copy of all registered event handlers, sorted by order\n */\n get handlers(): EventHandler<EVENT>[] {\n return [...this.eventHandlers];\n }\n\n destroy() {\n this.eventHandlers = [];\n }\n\n protected async handleEvent(handler: EventHandler<EVENT>, event: EVENT): Promise<void> {\n try {\n handler.handle(event);\n } catch (e) {\n console.warn(`Event handler error for ${handler.name}:`, e);\n }\n }\n\n abstract emit(event: EVENT): Promise<void>;\n\n abstract off(name: string): boolean;\n\n abstract on(handler: EventHandler<EVENT>): boolean;\n}","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Parallel implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers in parallel.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new ParallelTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // Both handlers execute in parallel\n * ```\n */\nexport class ParallelTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n\n /**\n * Creates a parallel typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers in parallel\n *\n * Handlers are executed concurrently. Once-only handlers are removed after all executions complete.\n * Errors in individual handlers are logged but do not affect other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n const promises = this.eventHandlers.map(async handler => {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n });\n await Promise.all(promises);\n if (onceHandlers.length > 0) {\n this.eventHandlers = this.eventHandlers.filter(\n item => !onceHandlers.includes(item),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = original.filter(item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = [...original, handler];\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { toSorted } from '@ahoo-wang/fetcher';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Serial implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers serially in order of priority.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new SerialTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // handler1 executes first, then handler2\n * ```\n */\nexport class SerialTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n\n /**\n * Creates an in-memory typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers serially\n *\n * Handlers are executed in order of their priority. Once-only handlers are removed after execution.\n * Errors in individual handlers are logged but do not stop other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n for (const handler of this.eventHandlers) {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n }\n if (onceHandlers.length > 0) {\n this.eventHandlers = toSorted(\n this.eventHandlers.filter(item => !onceHandlers.includes(item)),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = toSorted(original, item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = toSorted([...original, handler]);\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport class BroadcastChannelMessenger implements CrossTabMessenger {\n private readonly broadcastChannel: BroadcastChannel;\n\n constructor(channelName: string) {\n this.broadcastChannel = new BroadcastChannel(channelName);\n }\n\n postMessage(message: any): void {\n this.broadcastChannel.postMessage(message);\n }\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages, or undefined to remove handler\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.broadcastChannel.onmessage = (event: MessageEvent) => {\n handler(event.data);\n };\n }\n\n /**\n * Close the messenger and clean up resources\n *\n * After calling close(), the messenger cannot be used again.\n */\n close(): void {\n this.broadcastChannel.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport interface StorageMessengerOptions {\n channelName: string;\n /** Storage instance to use. Defaults to localStorage */\n storage?: Storage;\n ttl?: number;\n cleanupInterval?: number;\n}\n\nexport interface StorageMessage {\n data: any;\n timestamp: number;\n}\n\nconst DEFAULT_TTL = 1000;\nconst DEFAULT_CLEANUP_INTERVAL = 60000;\n\nexport class StorageMessenger implements CrossTabMessenger {\n private readonly channelName: string;\n private readonly storage: Storage;\n private messageHandler?: CrossTabMessageHandler;\n private readonly messageKeyPrefix: string;\n private readonly ttl: number;\n private readonly cleanupInterval: number;\n private cleanupTimer?: number;\n private readonly storageEventHandler = (event: StorageEvent) => {\n if (\n event.storageArea !== this.storage ||\n !event.key?.startsWith(this.messageKeyPrefix) ||\n !event.newValue\n ) {\n return;\n }\n try {\n const storageMessage = JSON.parse(event.newValue) as StorageMessage;\n this.messageHandler?.(storageMessage.data);\n } catch (error) {\n console.warn('Failed to parse storage message:', error);\n }\n };\n\n constructor(options: StorageMessengerOptions) {\n this.channelName = options.channelName;\n this.storage = options.storage ?? localStorage;\n this.messageKeyPrefix = `_storage_msg_${this.channelName}`;\n this.ttl = options.ttl ?? DEFAULT_TTL;\n this.cleanupInterval = options.cleanupInterval ?? DEFAULT_CLEANUP_INTERVAL;\n this.cleanupTimer = window.setInterval(\n () => this.cleanup(),\n this.cleanupInterval,\n );\n window.addEventListener('storage', this.storageEventHandler);\n }\n\n private generateMessageKey(): string {\n return `${this.messageKeyPrefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n /**\n * Send a message to other tabs/windows via localStorage\n */\n postMessage(message: any): void {\n const key = this.generateMessageKey();\n const storageMessage: StorageMessage = {\n data: message,\n timestamp: Date.now(),\n };\n this.storage.setItem(key, JSON.stringify(storageMessage));\n // Delay removal to ensure all listeners have processed the event\n setTimeout(() => this.storage.removeItem(key), this.ttl);\n }\n\n /**\n * Set the message handler for incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.messageHandler = handler;\n }\n\n /**\n * Clean up expired messages from storage\n */\n private cleanup(): void {\n const now = Date.now();\n const keysToRemove: string[] = [];\n for (let i = 0; i < this.storage.length; i++) {\n const key = this.storage.key(i);\n if (key?.startsWith(this.messageKeyPrefix)) {\n try {\n const value = this.storage.getItem(key);\n if (value) {\n const message: StorageMessage = JSON.parse(value);\n if (now > message.timestamp + this.ttl) {\n keysToRemove.push(key);\n }\n }\n } catch {\n // Invalid data, remove it\n keysToRemove.push(key);\n }\n }\n }\n keysToRemove.forEach(key => this.storage.removeItem(key));\n }\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void {\n if (this.cleanupTimer) {\n clearInterval(this.cleanupTimer);\n }\n window.removeEventListener('storage', this.storageEventHandler);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BroadcastChannelMessenger } from './broadcastChannelMessenger';\nimport { StorageMessenger } from './storageMessenger';\n\nexport type CrossTabMessageHandler = (message: any) => void;\n\n/**\n * Interface for cross-tab communication messengers\n *\n * Provides a unified API for different cross-tab communication mechanisms\n * like BroadcastChannel, StorageEvent, SharedWorker, etc.\n */\nexport interface CrossTabMessenger {\n /**\n * Send a message to other tabs/windows\n *\n * @param message - The data to send\n */\n postMessage(message: any): void;\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler);\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void;\n}\n\nexport function isBroadcastChannelSupported(): boolean {\n return (\n typeof BroadcastChannel !== 'undefined' &&\n typeof BroadcastChannel.prototype?.postMessage === 'function'\n );\n}\n\nexport function isStorageEventSupported(): boolean {\n return (\n typeof StorageEvent !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window.addEventListener === 'function' &&\n (typeof localStorage !== 'undefined' ||\n typeof sessionStorage !== 'undefined')\n );\n}\n\nexport function createCrossTabMessenger(\n channelName: string,\n): CrossTabMessenger | undefined {\n if (isBroadcastChannelSupported()) {\n return new BroadcastChannelMessenger(channelName);\n }\n\n if (isStorageEventSupported()) {\n return new StorageMessenger({ channelName });\n }\n\n return undefined;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\nimport { createCrossTabMessenger, CrossTabMessenger } from './messengers';\n\n/**\n * Configuration options for BroadcastTypedEventBus\n *\n * @template EVENT - The event type this bus will handle\n */\nexport interface BroadcastTypedEventBusOptions<EVENT> {\n /**\n * The underlying event bus that handles local event processing and storage.\n * This bus manages event handlers and local event emission.\n */\n delegate: TypedEventBus<EVENT>;\n\n /**\n * Optional messenger for cross-tab/window communication.\n * If not provided, a default BroadcastChannel-based messenger will be created\n * using the pattern `_broadcast_:{type}`. Must be a valid CrossTabMessenger\n * implementation when provided.\n */\n messenger?: CrossTabMessenger;\n}\n\n/**\n * Broadcast event bus that enables cross-tab/window communication\n *\n * This class extends a local TypedEventBus with cross-context broadcasting capabilities.\n * When events are emitted, they are first processed locally by the delegate bus, then\n * broadcasted to other browser contexts (tabs, windows, etc.) through the provided messenger.\n *\n * Incoming broadcast messages from other contexts are automatically forwarded to the\n * local delegate bus for processing by registered event handlers.\n *\n * @template EVENT - The event type this bus handles (must be serializable for cross-context transport)\n *\n * @example Basic usage with default messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create broadcast event bus with default messenger\n * const bus = new BroadcastTypedEventBus({\n * delegate\n * // messenger will be auto-created as '_broadcast_:user-events'\n * });\n *\n * // Register event handler\n * bus.on({\n * name: 'user-login',\n * order: 1,\n * handle: (username: string) => console.log(`User ${username} logged in`)\n * });\n *\n * // Emit event (will be processed locally and broadcasted to other tabs)\n * await bus.emit('john-doe');\n * ```\n *\n * @example Using custom messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { createCrossTabMessenger } from './messengers';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create custom cross-tab messenger\n * const messenger = createCrossTabMessenger('my-custom-channel');\n *\n * // Create broadcast event bus\n * const bus = new BroadcastTypedEventBus({\n * delegate,\n * messenger\n * });\n *\n * // Register event handler and emit events...\n * ```\n *\n * @example Using custom messenger implementation\n * ```typescript\n * class CustomMessenger implements CrossTabMessenger {\n * // ... implementation\n * }\n *\n * const customMessenger = new CustomMessenger();\n * const bus = new BroadcastTypedEventBus({\n * delegate: new SerialTypedEventBus('events'),\n * messenger: customMessenger\n * });\n * ```\n */\nexport class BroadcastTypedEventBus<EVENT> implements TypedEventBus<EVENT> {\n public readonly type: EventType;\n private readonly delegate: TypedEventBus<EVENT>;\n private messenger: CrossTabMessenger;\n\n /**\n * Creates a new broadcast event bus with cross-context communication\n *\n * @param options - Configuration object containing delegate bus and optional messenger\n * @throws {Error} If messenger creation fails when no messenger is provided\n */\n constructor(options: BroadcastTypedEventBusOptions<EVENT>) {\n this.delegate = options.delegate;\n this.type = this.delegate.type;\n const messenger =\n options.messenger ?? createCrossTabMessenger(`_broadcast_:${this.type}`);\n if (!messenger) {\n throw new Error('Messenger setup failed');\n }\n this.messenger = messenger;\n this.messenger.onmessage = async (event: EVENT) => {\n await this.delegate.emit(event);\n };\n }\n\n /**\n * Returns a copy of all currently registered event handlers\n *\n * This getter delegates to the underlying event bus and returns the current\n * list of handlers that will process incoming events.\n *\n * @returns Array of event handlers registered with this bus\n */\n get handlers(): EventHandler<EVENT>[] {\n return this.delegate.handlers;\n }\n\n /**\n * Emits an event locally and broadcasts it to other browser contexts\n *\n * This method first processes the event through the local delegate bus,\n * allowing all registered local handlers to process it. Then, if successful,\n * the event is broadcasted to other tabs/windows through the messenger.\n *\n * Note: If broadcasting fails (e.g., due to messenger errors), the local\n * emission is still completed and a warning is logged to console.\n *\n * @param event - The event data to emit and broadcast\n * @returns Promise that resolves when local processing is complete\n * @throws Propagates any errors from local event processing\n */\n async emit(event: EVENT): Promise<void> {\n await this.delegate.emit(event);\n this.messenger.postMessage(event);\n }\n\n /**\n * Removes an event handler by its registered name\n *\n * This method delegates to the underlying event bus to remove the specified\n * handler. The handler will no longer receive events emitted to this bus.\n *\n * @param name - The unique name of the handler to remove\n * @returns true if a handler with the given name was found and removed, false otherwise\n */\n off(name: string): boolean {\n return this.delegate.off(name);\n }\n\n /**\n * Registers a new event handler with this bus\n *\n * The handler will receive all events emitted to this bus, both locally\n * generated and received from other browser contexts via broadcasting.\n *\n * @param handler - The event handler configuration to register\n * @returns true if the handler was successfully added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n return this.delegate.on(handler);\n }\n\n /**\n * Cleans up resources and stops cross-context communication\n *\n * This method closes the messenger connection, preventing further\n * cross-tab communication. Local event handling continues to work\n * through the delegate bus. After calling destroy(), the bus should\n * not be used for broadcasting operations.\n *\n * Note: This does not remove event handlers or affect local event processing.\n */\n destroy(): void {\n this.messenger.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Interface for generating unique names with a prefix\n */\nexport interface NameGenerator {\n generate(prefix: string): string;\n}\n\n/**\n * Default implementation of NameGenerator that generates names with incrementing counters\n */\nexport class DefaultNameGenerator implements NameGenerator {\n private namingCounter: number = 0;\n\n /**\n * Generates a unique name by appending an incrementing counter to the prefix\n * @param prefix - The prefix for the generated name\n * @returns The generated unique name\n */\n generate(prefix: string): string {\n this.namingCounter++;\n return `${prefix}_${this.namingCounter}`;\n }\n}\n\n/**\n * Default instance of NameGenerator\n */\nexport const nameGenerator = new DefaultNameGenerator();\n"],"names":["EventBus","typeEventBusSupplier","type","handler","bus","name","event","AbstractTypedEventBus","e","ParallelTypedEventBus","onceHandlers","promises","item","original","SerialTypedEventBus","toSorted","BroadcastChannelMessenger","channelName","message","DEFAULT_TTL","DEFAULT_CLEANUP_INTERVAL","StorageMessenger","options","storageMessage","error","key","now","keysToRemove","i","value","isBroadcastChannelSupported","isStorageEventSupported","createCrossTabMessenger","BroadcastTypedEventBus","messenger","DefaultNameGenerator","prefix","nameGenerator"],"mappings":"uSAkCO,MAAMA,CAAoD,CAQ/D,YAA6BC,EAA4C,CAA5C,KAAA,qBAAAA,EAP7B,KAAiB,UAAoD,GAQrE,CAUA,GACEC,EACAC,EACS,CACT,IAAIC,EAAM,KAAK,MAAM,IAAIF,CAAI,EAC7B,OAAKE,IACHA,EAAM,KAAK,qBAAqBF,CAAI,EACpC,KAAK,MAAM,IAAIA,EAAME,CAAG,GAEnBA,GAAK,GAAGD,CAAO,GAAK,EAC7B,CAUA,IACED,EACAG,EACS,CACT,OAAO,KAAK,MAAM,IAAIH,CAAI,GAAG,IAAIG,CAAI,GAAK,EAC5C,CAUA,KACEH,EACAI,EACsB,CACtB,OAAO,KAAK,MAAM,IAAIJ,CAAI,GAAG,KAAKI,CAAK,CACzC,CAKA,SAAgB,CACd,UAAWF,KAAO,KAAK,MAAM,OAAA,EAC3BA,EAAI,QAAA,EAEN,KAAK,MAAM,MAAA,CACb,CACF,CCxFO,MAAeG,CAA6D,CAA5E,aAAA,CACL,KAAU,cAAuC,CAAA,CAAC,CAMlD,IA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ACF,CAKO,MAAMC,EAAgB,IAAIF"}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/eventBus.ts","../src/abstractTypedEventBus.ts","../src/parallelTypedEventBus.ts","../src/serialTypedEventBus.ts","../src/messengers/broadcastChannelMessenger.ts","../src/messengers/storageMessenger.ts","../src/messengers/crossTabMessenger.ts","../src/broadcastTypedEventBus.ts","../src/nameGenerator.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { TypedEventBus } from './typedEventBus';\n\n/**\n * Supplier function for creating TypedEventBus instances by event type\n */\nexport type TypeEventBusSupplier = (type: EventType) => TypedEventBus<unknown>;\n\n/**\n * Generic event bus that manages multiple event types using lazy-loaded TypedEventBus instances\n *\n * @template Events - A record mapping event types to their event data types\n *\n * @example\n * ```typescript\n * const supplier = (type: EventType) => new SerialTypedEventBus(type);\n * const bus = new EventBus<{ 'user-login': string; 'order-update': number }>(supplier);\n * bus.on('user-login', { name: 'logger', order: 1, handle: (event) => console.log(event) });\n * await bus.emit('user-login', 'john-doe');\n * ```\n */\nexport class EventBus<Events extends Record<EventType, unknown>> {\n private readonly buses: Map<EventType, TypedEventBus<unknown>> = new Map();\n\n /**\n * Creates a generic event bus\n *\n * @param typeEventBusSupplier - Function to create TypedEventBus for specific event types\n */\n constructor(private readonly typeEventBusSupplier: TypeEventBusSupplier) {}\n\n /**\n * Adds an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to listen for\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on<Key extends EventType>(\n type: Key,\n handler: EventHandler<Events[Key]>,\n ): boolean {\n let bus = this.buses.get(type);\n if (!bus) {\n bus = this.typeEventBusSupplier(type);\n this.buses.set(type, bus);\n }\n return bus?.on(handler) ?? false;\n }\n\n /**\n * Removes an event handler for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type\n * @param name - The name of the event handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off<Key extends EventType>(type: Key, name: string): boolean {\n return this.buses.get(type)?.off(name) ?? false;\n }\n\n /**\n * Emits an event for a specific event type\n *\n * @template Key - The event type\n * @param type - The event type to emit\n * @param event - The event data\n * @returns Promise if the underlying bus is async, void otherwise\n */\n emit<Key extends EventType>(\n type: Key,\n event: Events[Key],\n ): void | Promise<void> {\n return this.buses.get(type)?.emit(event);\n }\n\n /**\n * Cleans up all managed event buses\n */\n destroy(): void {\n for (const bus of this.buses.values()) {\n bus.destroy();\n }\n this.buses.clear();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\n\nexport abstract class AbstractTypedEventBus<EVENT>\n implements TypedEventBus<EVENT>\n{\n protected eventHandlers: EventHandler<EVENT>[] = [];\n abstract type: EventType;\n\n /**\n * Gets a copy of all registered event handlers, sorted by order\n */\n get handlers(): EventHandler<EVENT>[] {\n return [...this.eventHandlers];\n }\n\n destroy() {\n this.eventHandlers = [];\n }\n\n protected async handleEvent(\n handler: EventHandler<EVENT>,\n event: EVENT,\n ): Promise<void> {\n try {\n handler.handle(event);\n } catch (e) {\n console.warn(`Event handler error for ${handler.name}:`, e);\n }\n }\n\n abstract emit(event: EVENT): Promise<void>;\n\n abstract off(name: string): boolean;\n\n abstract on(handler: EventHandler<EVENT>): boolean;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Parallel implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers in parallel.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new ParallelTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // Both handlers execute in parallel\n * ```\n */\nexport class ParallelTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n /**\n * Creates a parallel typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers in parallel\n *\n * Handlers are executed concurrently. Once-only handlers are removed after all executions complete.\n * Errors in individual handlers are logged but do not affect other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n const promises = this.eventHandlers.map(async handler => {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n });\n await Promise.all(promises);\n if (onceHandlers.length > 0) {\n this.eventHandlers = this.eventHandlers.filter(\n item => !onceHandlers.includes(item),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = original.filter(item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = [...original, handler];\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { EventHandler, EventType } from './types';\nimport { toSorted } from '@ahoo-wang/fetcher';\nimport { AbstractTypedEventBus } from './abstractTypedEventBus';\n\n/**\n * Serial implementation of TypedEventBus\n *\n * Provides an in-memory event bus that executes event handlers serially in order of priority.\n * Supports ordering and once-only execution of handlers.\n *\n * @template EVENT - The type of events this bus handles\n *\n * @example\n * ```typescript\n * const bus = new SerialTypedEventBus<string>('test');\n * bus.on({ name: 'handler1', order: 1, handle: (event) => console.log(event) });\n * bus.on({ name: 'handler2', order: 2, handle: (event) => console.log('second', event) });\n * await bus.emit('hello'); // handler1 executes first, then handler2\n * ```\n */\nexport class SerialTypedEventBus<EVENT> extends AbstractTypedEventBus<EVENT> {\n /**\n * Creates an in-memory typed event bus\n *\n * @param type - The event type identifier for this bus\n */\n constructor(public readonly type: EventType) {\n super();\n }\n\n /**\n * Emits an event to all registered handlers serially\n *\n * Handlers are executed in order of their priority. Once-only handlers are removed after execution.\n * Errors in individual handlers are logged but do not stop other handlers.\n *\n * @param event - The event to emit\n */\n async emit(event: EVENT): Promise<void> {\n const onceHandlers: EventHandler<EVENT>[] = [];\n for (const handler of this.eventHandlers) {\n await this.handleEvent(handler, event);\n if (handler.once) {\n onceHandlers.push(handler);\n }\n }\n if (onceHandlers.length > 0) {\n this.eventHandlers = toSorted(\n this.eventHandlers.filter(item => !onceHandlers.includes(item)),\n );\n }\n }\n\n /**\n * Removes an event handler by name\n *\n * @param name - The name of the handler to remove\n * @returns true if a handler was removed, false otherwise\n */\n off(name: string): boolean {\n const original = this.eventHandlers;\n if (!original.some(item => item.name === name)) {\n return false;\n }\n this.eventHandlers = toSorted(original, item => item.name !== name);\n return true;\n }\n\n /**\n * Adds an event handler if not already present\n *\n * Handlers are sorted by their order property after addition.\n *\n * @param handler - The event handler to add\n * @returns true if the handler was added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n const original = this.eventHandlers;\n if (original.some(item => item.name === handler.name)) {\n return false;\n }\n this.eventHandlers = toSorted([...original, handler]);\n return true;\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport class BroadcastChannelMessenger implements CrossTabMessenger {\n private readonly broadcastChannel: BroadcastChannel;\n\n constructor(channelName: string) {\n this.broadcastChannel = new BroadcastChannel(channelName);\n }\n\n postMessage(message: any): void {\n this.broadcastChannel.postMessage(message);\n }\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages, or undefined to remove handler\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.broadcastChannel.onmessage = (event: MessageEvent) => {\n handler(event.data);\n };\n }\n\n /**\n * Close the messenger and clean up resources\n *\n * After calling close(), the messenger cannot be used again.\n */\n close(): void {\n this.broadcastChannel.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CrossTabMessenger, CrossTabMessageHandler } from './crossTabMessenger';\n\nexport interface StorageMessengerOptions {\n channelName: string;\n /** Storage instance to use. Defaults to localStorage */\n storage?: Storage;\n ttl?: number;\n cleanupInterval?: number;\n}\n\nexport interface StorageMessage {\n data: any;\n timestamp: number;\n}\n\nconst DEFAULT_TTL = 1000;\nconst DEFAULT_CLEANUP_INTERVAL = 60000;\n\nexport class StorageMessenger implements CrossTabMessenger {\n private readonly channelName: string;\n private readonly storage: Storage;\n private messageHandler?: CrossTabMessageHandler;\n private readonly messageKeyPrefix: string;\n private readonly ttl: number;\n private readonly cleanupInterval: number;\n private cleanupTimer?: number;\n private readonly storageEventHandler = (event: StorageEvent) => {\n if (\n event.storageArea !== this.storage ||\n !event.key?.startsWith(this.messageKeyPrefix) ||\n !event.newValue\n ) {\n return;\n }\n try {\n const storageMessage = JSON.parse(event.newValue) as StorageMessage;\n this.messageHandler?.(storageMessage.data);\n } catch (error) {\n console.warn('Failed to parse storage message:', error);\n }\n };\n\n constructor(options: StorageMessengerOptions) {\n this.channelName = options.channelName;\n this.storage = options.storage ?? localStorage;\n this.messageKeyPrefix = `_storage_msg_${this.channelName}`;\n this.ttl = options.ttl ?? DEFAULT_TTL;\n this.cleanupInterval = options.cleanupInterval ?? DEFAULT_CLEANUP_INTERVAL;\n this.cleanupTimer = window.setInterval(\n () => this.cleanup(),\n this.cleanupInterval,\n );\n window.addEventListener('storage', this.storageEventHandler);\n }\n\n private generateMessageKey(): string {\n return `${this.messageKeyPrefix}_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n /**\n * Send a message to other tabs/windows via localStorage\n */\n postMessage(message: any): void {\n const key = this.generateMessageKey();\n const storageMessage: StorageMessage = {\n data: message,\n timestamp: Date.now(),\n };\n this.storage.setItem(key, JSON.stringify(storageMessage));\n // Delay removal to ensure all listeners have processed the event\n setTimeout(() => this.storage.removeItem(key), this.ttl);\n }\n\n /**\n * Set the message handler for incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler) {\n this.messageHandler = handler;\n }\n\n /**\n * Clean up expired messages from storage\n */\n private cleanup(): void {\n const now = Date.now();\n const keysToRemove: string[] = [];\n for (let i = 0; i < this.storage.length; i++) {\n const key = this.storage.key(i);\n if (key?.startsWith(this.messageKeyPrefix)) {\n try {\n const value = this.storage.getItem(key);\n if (value) {\n const message: StorageMessage = JSON.parse(value);\n if (now > message.timestamp + this.ttl) {\n keysToRemove.push(key);\n }\n }\n } catch {\n // Invalid data, remove it\n keysToRemove.push(key);\n }\n }\n }\n keysToRemove.forEach(key => this.storage.removeItem(key));\n }\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void {\n if (this.cleanupTimer) {\n clearInterval(this.cleanupTimer);\n }\n window.removeEventListener('storage', this.storageEventHandler);\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { BroadcastChannelMessenger } from './broadcastChannelMessenger';\nimport { StorageMessenger } from './storageMessenger';\n\nexport type CrossTabMessageHandler = (message: any) => void;\n\n/**\n * Interface for cross-tab communication messengers\n *\n * Provides a unified API for different cross-tab communication mechanisms\n * like BroadcastChannel, StorageEvent, SharedWorker, etc.\n */\nexport interface CrossTabMessenger {\n /**\n * Send a message to other tabs/windows\n *\n * @param message - The data to send\n */\n postMessage(message: any): void;\n\n /**\n * Set the message handler for incoming messages\n *\n * @param handler - Function to handle incoming messages\n */\n set onmessage(handler: CrossTabMessageHandler);\n\n /**\n * Close the messenger and clean up resources\n */\n close(): void;\n}\n\nexport function isBroadcastChannelSupported(): boolean {\n return (\n typeof BroadcastChannel !== 'undefined' &&\n typeof BroadcastChannel.prototype?.postMessage === 'function'\n );\n}\n\nexport function isStorageEventSupported(): boolean {\n return (\n typeof StorageEvent !== 'undefined' &&\n typeof window !== 'undefined' &&\n typeof window.addEventListener === 'function' &&\n (typeof localStorage !== 'undefined' ||\n typeof sessionStorage !== 'undefined')\n );\n}\n\nexport function createCrossTabMessenger(\n channelName: string,\n): CrossTabMessenger | undefined {\n if (isBroadcastChannelSupported()) {\n return new BroadcastChannelMessenger(channelName);\n }\n\n if (isStorageEventSupported()) {\n return new StorageMessenger({ channelName });\n }\n\n return undefined;\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { TypedEventBus } from './typedEventBus';\nimport { EventHandler, EventType } from './types';\nimport { createCrossTabMessenger, CrossTabMessenger } from './messengers';\n\n/**\n * Configuration options for BroadcastTypedEventBus\n *\n * @template EVENT - The event type this bus will handle\n */\nexport interface BroadcastTypedEventBusOptions<EVENT> {\n /**\n * The underlying event bus that handles local event processing and storage.\n * This bus manages event handlers and local event emission.\n */\n delegate: TypedEventBus<EVENT>;\n\n /**\n * Optional messenger for cross-tab/window communication.\n * If not provided, a default BroadcastChannel-based messenger will be created\n * using the pattern `_broadcast_:{type}`. Must be a valid CrossTabMessenger\n * implementation when provided.\n */\n messenger?: CrossTabMessenger;\n}\n\n/**\n * Broadcast event bus that enables cross-tab/window communication\n *\n * This class extends a local TypedEventBus with cross-context broadcasting capabilities.\n * When events are emitted, they are first processed locally by the delegate bus, then\n * broadcasted to other browser contexts (tabs, windows, etc.) through the provided messenger.\n *\n * Incoming broadcast messages from other contexts are automatically forwarded to the\n * local delegate bus for processing by registered event handlers.\n *\n * @template EVENT - The event type this bus handles (must be serializable for cross-context transport)\n *\n * @example Basic usage with default messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create broadcast event bus with default messenger\n * const bus = new BroadcastTypedEventBus({\n * delegate\n * // messenger will be auto-created as '_broadcast_:user-events'\n * });\n *\n * // Register event handler\n * bus.on({\n * name: 'user-login',\n * order: 1,\n * handle: (username: string) => console.log(`User ${username} logged in`)\n * });\n *\n * // Emit event (will be processed locally and broadcasted to other tabs)\n * await bus.emit('john-doe');\n * ```\n *\n * @example Using custom messenger\n * ```typescript\n * import { SerialTypedEventBus } from './serialTypedEventBus';\n * import { createCrossTabMessenger } from './messengers';\n * import { BroadcastTypedEventBus } from './broadcastTypedEventBus';\n *\n * // Create local event bus\n * const delegate = new SerialTypedEventBus<string>('user-events');\n *\n * // Create custom cross-tab messenger\n * const messenger = createCrossTabMessenger('my-custom-channel');\n *\n * // Create broadcast event bus\n * const bus = new BroadcastTypedEventBus({\n * delegate,\n * messenger\n * });\n *\n * // Register event handler and emit events...\n * ```\n *\n * @example Using custom messenger implementation\n * ```typescript\n * class CustomMessenger implements CrossTabMessenger {\n * // ... implementation\n * }\n *\n * const customMessenger = new CustomMessenger();\n * const bus = new BroadcastTypedEventBus({\n * delegate: new SerialTypedEventBus('events'),\n * messenger: customMessenger\n * });\n * ```\n */\nexport class BroadcastTypedEventBus<EVENT> implements TypedEventBus<EVENT> {\n public readonly type: EventType;\n private readonly delegate: TypedEventBus<EVENT>;\n private messenger: CrossTabMessenger;\n\n /**\n * Creates a new broadcast event bus with cross-context communication\n *\n * @param options - Configuration object containing delegate bus and optional messenger\n * @throws {Error} If messenger creation fails when no messenger is provided\n */\n constructor(options: BroadcastTypedEventBusOptions<EVENT>) {\n this.delegate = options.delegate;\n this.type = this.delegate.type;\n const messenger =\n options.messenger ?? createCrossTabMessenger(`_broadcast_:${this.type}`);\n if (!messenger) {\n throw new Error('Messenger setup failed');\n }\n this.messenger = messenger;\n this.messenger.onmessage = async (event: EVENT) => {\n await this.delegate.emit(event);\n };\n }\n\n /**\n * Returns a copy of all currently registered event handlers\n *\n * This getter delegates to the underlying event bus and returns the current\n * list of handlers that will process incoming events.\n *\n * @returns Array of event handlers registered with this bus\n */\n get handlers(): EventHandler<EVENT>[] {\n return this.delegate.handlers;\n }\n\n /**\n * Emits an event locally and broadcasts it to other browser contexts\n *\n * This method first processes the event through the local delegate bus,\n * allowing all registered local handlers to process it. Then, if successful,\n * the event is broadcasted to other tabs/windows through the messenger.\n *\n * Note: If broadcasting fails (e.g., due to messenger errors), the local\n * emission is still completed and a warning is logged to console.\n *\n * @param event - The event data to emit and broadcast\n * @returns Promise that resolves when local processing is complete\n * @throws Propagates any errors from local event processing\n */\n async emit(event: EVENT): Promise<void> {\n await this.delegate.emit(event);\n this.messenger.postMessage(event);\n }\n\n /**\n * Removes an event handler by its registered name\n *\n * This method delegates to the underlying event bus to remove the specified\n * handler. The handler will no longer receive events emitted to this bus.\n *\n * @param name - The unique name of the handler to remove\n * @returns true if a handler with the given name was found and removed, false otherwise\n */\n off(name: string): boolean {\n return this.delegate.off(name);\n }\n\n /**\n * Registers a new event handler with this bus\n *\n * The handler will receive all events emitted to this bus, both locally\n * generated and received from other browser contexts via broadcasting.\n *\n * @param handler - The event handler configuration to register\n * @returns true if the handler was successfully added, false if a handler with the same name already exists\n */\n on(handler: EventHandler<EVENT>): boolean {\n return this.delegate.on(handler);\n }\n\n /**\n * Cleans up resources and stops cross-context communication\n *\n * This method closes the messenger connection, preventing further\n * cross-tab communication. Local event handling continues to work\n * through the delegate bus. After calling destroy(), the bus should\n * not be used for broadcasting operations.\n *\n * Note: This does not remove event handlers or affect local event processing.\n */\n destroy(): void {\n this.messenger.close();\n }\n}\n","/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Interface for generating unique names with a prefix\n */\nexport interface NameGenerator {\n generate(prefix: string): string;\n}\n\n/**\n * Default implementation of NameGenerator that generates names with incrementing counters\n */\nexport class DefaultNameGenerator implements NameGenerator {\n private namingCounter: number = 0;\n\n /**\n * Generates a unique name by appending an incrementing counter to the prefix\n * @param prefix - The prefix for the generated name\n * @returns The generated unique name\n */\n generate(prefix: string): string {\n this.namingCounter++;\n return `${prefix}_${this.namingCounter}`;\n }\n}\n\n/**\n * Default instance of NameGenerator\n */\nexport const nameGenerator = new DefaultNameGenerator();\n"],"names":["EventBus","typeEventBusSupplier","type","handler","bus","name","event","AbstractTypedEventBus","e","ParallelTypedEventBus","onceHandlers","promises","item","original","SerialTypedEventBus","toSorted","BroadcastChannelMessenger","channelName","message","DEFAULT_TTL","DEFAULT_CLEANUP_INTERVAL","StorageMessenger","options","storageMessage","error","key","now","keysToRemove","i","value","isBroadcastChannelSupported","isStorageEventSupported","createCrossTabMessenger","BroadcastTypedEventBus","messenger","DefaultNameGenerator","prefix","nameGenerator"],"mappings":"uSAkCO,MAAMA,CAAoD,CAQ/D,YAA6BC,EAA4C,CAA5C,KAAA,qBAAAA,EAP7B,KAAiB,UAAoD,GAOK,CAU1E,GACEC,EACAC,EACS,CACT,IAAIC,EAAM,KAAK,MAAM,IAAIF,CAAI,EAC7B,OAAKE,IACHA,EAAM,KAAK,qBAAqBF,CAAI,EACpC,KAAK,MAAM,IAAIA,EAAME,CAAG,GAEnBA,GAAK,GAAGD,CAAO,GAAK,EAC7B,CAUA,IAA2BD,EAAWG,EAAuB,CAC3D,OAAO,KAAK,MAAM,IAAIH,CAAI,GAAG,IAAIG,CAAI,GAAK,EAC5C,CAUA,KACEH,EACAI,EACsB,CACtB,OAAO,KAAK,MAAM,IAAIJ,CAAI,GAAG,KAAKI,CAAK,CACzC,CAKA,SAAgB,CACd,UAAWF,KAAO,KAAK,MAAM,OAAA,EAC3BA,EAAI,QAAA,EAEN,KAAK,MAAM,MAAA,CACb,CACF,CCpFO,MAAeG,CAEtB,CAFO,aAAA,CAGL,KAAU,cAAuC,CAAA,CAAC,CAMlD,IAAI,UAAkC,CACpC,MAAO,CAAC,GAAG,KAAK,aAAa,CAC/B,CAEA,SAAU,CACR,KAAK,cAAgB,CAAA,CACvB,CA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"","sources":["../src/parallelTypedEventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,qBAAqB,CAAC,KAAK,CAAE,SAAQ,qBAAqB,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"parallelTypedEventBus.d.ts","sourceRoot":"","sources":["../src/parallelTypedEventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,qBAAqB,CAAC,KAAK,CAAE,SAAQ,qBAAqB,CAAC,KAAK,CAAC;aAMhD,IAAI,EAAE,SAAS;IAL3C;;;;OAIG;gBACyB,IAAI,EAAE,SAAS;IAI3C;;;;;;;OAOG;IACG,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBvC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAS1B;;;;;;;OAOG;IACH,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,OAAO;CAQ1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialTypedEventBus.d.ts","sourceRoot":"","sources":["../src/serialTypedEventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAmB,CAAC,KAAK,CAAE,SAAQ,qBAAqB,CAAC,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"serialTypedEventBus.d.ts","sourceRoot":"","sources":["../src/serialTypedEventBus.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAElD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAmB,CAAC,KAAK,CAAE,SAAQ,qBAAqB,CAAC,KAAK,CAAC;aAM9C,IAAI,EAAE,SAAS;IAL3C;;;;OAIG;gBACyB,IAAI,EAAE,SAAS;IAI3C;;;;;;;OAOG;IACG,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAevC;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAS1B;;;;;;;OAOG;IACH,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,OAAO;CAQ1C"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEvE,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,WAAW,YAAY,CAAC,KAAK,CAAE,SAAQ,YAAY,EAAE,cAAc;IACvE,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5C"}
|