Skip to content

Commit

Permalink
feat(listenkey): add listenKey
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Dec 2, 2022
1 parent 9bd77ec commit e02880f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { listenerKey, senderKey } from './constant';
export { listenerKey, senderKey, listenKey } from './constant';

export * from './decorators';
export * from './transport';
Expand Down
8 changes: 6 additions & 2 deletions src/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
prefixKey,
transportType,
produceKey,
listenKey,
} from './constant';
import type {
EmitOptions,
Expand All @@ -35,6 +36,7 @@ const getListenName = (prefix: string, action: string) =>
*/
export abstract class Transport<T = any, P = any> {
private [listenerKey]: TransportOptions['listener'];
private [listenKey]: (options?: ListenerOptions) => void;
private [senderKey]: TransportOptions['sender'];
private [timeoutKey]: TransportOptions['timeout'];
private [prefixKey]: TransportOptions['prefix'];
Expand Down Expand Up @@ -87,7 +89,7 @@ export abstract class Transport<T = any, P = any> {
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);
Expand Down Expand Up @@ -126,7 +128,9 @@ export abstract class Transport<T = any, P = any> {
}
}
}
});
};

const dispose = this[listenerKey](this[listenKey]);

this.dispose =
typeof dispose === 'function'
Expand Down

0 comments on commit e02880f

Please sign in to comment.