diff --git a/package.json b/package.json index e71c697..0ca9701 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-transport", - "version": "3.2.1", + "version": "3.2.2", "description": "A simple and responsible transport", "main": "lib/index.js", "unpkg": "dist/index.umd.js", diff --git a/src/constant.ts b/src/constant.ts index 65b7c8a..a402f08 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,4 +1,5 @@ export const listenerKey: unique symbol = Symbol('listener'); +export const listenKey: unique symbol = Symbol('listen'); export const senderKey: unique symbol = Symbol('sender'); export const requestsMapKey: unique symbol = Symbol('requestsMap'); export const listensMapKey: unique symbol = Symbol('listensMapKey'); diff --git a/src/index.ts b/src/index.ts index 39f6afe..ef84d0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { listenerKey, senderKey } from './constant'; +export { listenerKey, senderKey, listenKey } from './constant'; export * from './decorators'; export * from './transport'; diff --git a/src/transport.ts b/src/transport.ts index 08c73fa..b7d5d00 100644 --- a/src/transport.ts +++ b/src/transport.ts @@ -10,6 +10,7 @@ import { prefixKey, transportType, produceKey, + listenKey, } from './constant'; import type { EmitOptions, @@ -35,6 +36,7 @@ const getListenName = (prefix: string, action: string) => */ export abstract class Transport { private [listenerKey]: TransportOptions['listener']; + private [listenKey]: (options?: ListenerOptions) => void; private [senderKey]: TransportOptions['sender']; private [timeoutKey]: TransportOptions['timeout']; private [prefixKey]: TransportOptions['prefix']; @@ -87,7 +89,7 @@ export abstract class Transport { this[produceKey](name, this[originalListensMapKey][name]); }); - const dispose = this[listenerKey]((options?: ListenerOptions) => { + this[listenKey] = (options?: ListenerOptions) => { if (verbose) { if (typeof verbose === 'function' && options) { verbose(options); @@ -126,7 +128,9 @@ export abstract class Transport { } } } - }); + }; + + const dispose = this[listenerKey](this[listenKey]); this.dispose = typeof dispose === 'function'