@polyv/utils 2.14.0-beta.3 → 2.14.0-beta.5

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/cjs/event.d.ts CHANGED
@@ -64,10 +64,14 @@ export type EventType = number | string | symbol;
64
64
  * 事件参数关系类型
65
65
  */
66
66
  export type EventRelationsType = Record<EventType, unknown>;
67
+ /**
68
+ * 事件回调后的类 response 函数
69
+ */
70
+ type EventHandlerCb = (res: unknown) => void;
67
71
  /**
68
72
  * 事件回调函数类型
69
73
  */
70
- export type EventHandler<Relations extends EventRelationsType, E extends EventType> = (params: Relations[E]) => unknown;
74
+ export type EventHandler<Relations extends EventRelationsType, E extends EventType> = (params: Relations[E], cb?: EventHandlerCb) => unknown;
71
75
  export declare class EventEmitter<Relations extends EventRelationsType = EventRelationsType, Events extends EventType = string> {
72
76
  /**
73
77
  * 事件回调存储器
@@ -104,10 +108,11 @@ export declare class EventEmitter<Relations extends EventRelationsType = EventRe
104
108
  * @param event 事件名
105
109
  * @param params 回调参数
106
110
  */
107
- emit<E extends Events>(event: E, params: Relations[E]): void;
111
+ emit<E extends Events>(event: E, params: Relations[E], cb?: EventHandlerCb): void;
108
112
  emit<E extends Events>(event: undefined extends Relations[E] ? E : never): void;
109
113
  /**
110
114
  * 销毁实例
111
115
  */
112
116
  destroy(): void;
113
117
  }
118
+ export {};
package/cjs/event.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=void 0;var EventEmitter=function(){function t(){this.__eventStore={}}return t.prototype.__addOnEvent=function(t,e,n,o){if(e&&n){var r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}},t.prototype.on=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("normal",t,e,n)},t.prototype.once=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("once",t,e,n)},t.prototype.off=function(t,e){var n=this.__eventStore[t];n&&(n=n.filter((function(t){return t.handler!==e})),this.__eventStore[t]=n)},t.prototype.emit=function(t,e){var n=this,o=this.__eventStore[t];o&&o.forEach((function(o){var r=o.type,i=o.handler,v=o.callbackHandler;"function"==typeof v&&v(e),"once"===r&&n.off(t,i)}))},t.prototype.destroy=function(){this.__eventStore={}},t}();exports.EventEmitter=EventEmitter;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.EventEmitter=void 0;var EventEmitter=function(){function t(){this.__eventStore={}}return t.prototype.__addOnEvent=function(t,e,n,o){if(e&&n){var r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}},t.prototype.on=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("normal",t,e,n)},t.prototype.once=function(t,e,n){void 0===n&&(n=this),this.__addOnEvent("once",t,e,n)},t.prototype.off=function(t,e){var n=this.__eventStore[t];n&&(n=n.filter((function(t){return t.handler!==e})),this.__eventStore[t]=n)},t.prototype.emit=function(t,e,n){var o=this,r=this.__eventStore[t];r&&r.forEach((function(r){var i=r.type,v=r.handler,_=r.callbackHandler;"function"==typeof _&&_(e,n),"once"===i&&o.off(t,v)}))},t.prototype.destroy=function(){this.__eventStore={}},t}();exports.EventEmitter=EventEmitter;
package/es/event.d.ts CHANGED
@@ -64,10 +64,14 @@ export type EventType = number | string | symbol;
64
64
  * 事件参数关系类型
65
65
  */
66
66
  export type EventRelationsType = Record<EventType, unknown>;
67
+ /**
68
+ * 事件回调后的类 response 函数
69
+ */
70
+ type EventHandlerCb = (res: unknown) => void;
67
71
  /**
68
72
  * 事件回调函数类型
69
73
  */
70
- export type EventHandler<Relations extends EventRelationsType, E extends EventType> = (params: Relations[E]) => unknown;
74
+ export type EventHandler<Relations extends EventRelationsType, E extends EventType> = (params: Relations[E], cb?: EventHandlerCb) => unknown;
71
75
  export declare class EventEmitter<Relations extends EventRelationsType = EventRelationsType, Events extends EventType = string> {
72
76
  /**
73
77
  * 事件回调存储器
@@ -104,10 +108,11 @@ export declare class EventEmitter<Relations extends EventRelationsType = EventRe
104
108
  * @param event 事件名
105
109
  * @param params 回调参数
106
110
  */
107
- emit<E extends Events>(event: E, params: Relations[E]): void;
111
+ emit<E extends Events>(event: E, params: Relations[E], cb?: EventHandlerCb): void;
108
112
  emit<E extends Events>(event: undefined extends Relations[E] ? E : never): void;
109
113
  /**
110
114
  * 销毁实例
111
115
  */
112
116
  destroy(): void;
113
117
  }
118
+ export {};
package/es/event.js CHANGED
@@ -1 +1 @@
1
- export class EventEmitter{constructor(){this.__eventStore={}}__addOnEvent(t,e,n,o){if(!e||!n)return;let r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}on(t,e,n=this){this.__addOnEvent("normal",t,e,n)}once(t,e,n=this){this.__addOnEvent("once",t,e,n)}off(t,e){let n=this.__eventStore[t];n&&(n=n.filter((t=>t.handler!==e)),this.__eventStore[t]=n)}emit(t,e){const n=this.__eventStore[t];n&&n.forEach((n=>{const{type:o,handler:r,callbackHandler:_}=n;"function"==typeof _&&_(e),"once"===o&&this.off(t,r)}))}destroy(){this.__eventStore={}}}
1
+ export class EventEmitter{constructor(){this.__eventStore={}}__addOnEvent(t,e,n,o){if(!e||!n)return;let r=this.__eventStore[e];r||(r=[]),r.push({type:t,handler:n,callbackHandler:n.bind(o)}),this.__eventStore[e]=r}on(t,e,n=this){this.__addOnEvent("normal",t,e,n)}once(t,e,n=this){this.__addOnEvent("once",t,e,n)}off(t,e){let n=this.__eventStore[t];n&&(n=n.filter((t=>t.handler!==e)),this.__eventStore[t]=n)}emit(t,e,n){const o=this.__eventStore[t];o&&o.forEach((o=>{const{type:r,handler:_,callbackHandler:s}=o;"function"==typeof s&&s(e,n),"once"===r&&this.off(t,_)}))}destroy(){this.__eventStore={}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polyv/utils",
3
- "version": "2.14.0-beta.3",
3
+ "version": "2.14.0-beta.5",
4
4
  "description": "Utility functions of Polyv frontend development.",
5
5
  "keywords": [
6
6
  "polyv",