Comparing version 4.0.10 to 4.0.11
@@ -0,26 +1,3 @@ | ||
import { Emitter } from "@servie/events"; | ||
/** | ||
* Event listener type. | ||
*/ | ||
declare type EventListener<T, K extends keyof T> = (...args: (T & Record<PropertyKey, any[]>)[K]) => void; | ||
/** | ||
* Wildcard event listener type. | ||
*/ | ||
declare type EachEventListener<T> = { | ||
[K in keyof T]: (type: K, ...args: (T & Record<PropertyKey, any[]>)[K]) => void; | ||
}[keyof T]; | ||
/** | ||
* Type-safe event emitter. | ||
*/ | ||
declare class Events<T> { | ||
all: Array<EachEventListener<T>>; | ||
any: { | ||
[K in keyof T]: Array<EventListener<T, K>>; | ||
}; | ||
on<K extends keyof T>(type: K, callback: EventListener<T, K>): void; | ||
off<K extends keyof T>(type: K, callback: EventListener<T, K>): void; | ||
each(callback: EachEventListener<T>): void; | ||
none(callback: EachEventListener<T>): void; | ||
emit<K extends keyof T>(type: K, ...args: (T & Record<PropertyKey, any[]>)[K]): void; | ||
} | ||
/** | ||
* Dictionary of supported signal events. | ||
@@ -40,3 +17,3 @@ */ | ||
*/ | ||
export declare class Signal extends Events<SignalEvents> { | ||
export declare class Signal extends Emitter<SignalEvents> { | ||
aborted: boolean; | ||
@@ -52,2 +29,1 @@ constructor(); | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("@servie/events"); | ||
/** | ||
* Type-safe event emitter. | ||
*/ | ||
class Events { | ||
constructor() { | ||
this.all = []; | ||
this.any = Object.create(null); | ||
} | ||
on(type, callback) { | ||
(this.any[type] = this.any[type] || []).push(callback); | ||
} | ||
off(type, callback) { | ||
const stack = this.any[type] || []; | ||
stack.splice(stack.indexOf(callback) >>> 0, 1); | ||
} | ||
each(callback) { | ||
this.all.push(callback); | ||
} | ||
none(callback) { | ||
this.all.splice(this.all.indexOf(callback) >>> 0, 1); | ||
} | ||
emit(type, ...args) { | ||
(this.any[type] || []).slice().forEach(fn => fn(...args)); | ||
this.all.slice().forEach(fn => fn(type, ...args)); | ||
} | ||
} | ||
/** | ||
* Helper to listen to an event once only. | ||
*/ | ||
function once(e, type, callback) { | ||
return e.on(type, function once(...args) { | ||
e.off(type, once); | ||
callback(...args); | ||
}); | ||
} | ||
/** | ||
* Standard signal used to communicate during `request` processing. | ||
*/ | ||
class Signal extends Events { | ||
class Signal extends events_1.Emitter { | ||
constructor() { | ||
@@ -46,3 +12,3 @@ super(); | ||
// Listen for the abort signal. | ||
once(this, "abort", () => (this.aborted = true)); | ||
this.on("abort", () => (this.aborted = true)); | ||
} | ||
@@ -49,0 +15,0 @@ } |
{ | ||
"name": "servie", | ||
"version": "4.0.10", | ||
"version": "4.0.11", | ||
"description": "Standard HTTP interfaces for HTTP clients and servers in node.js and browsers", | ||
@@ -103,4 +103,5 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@servie/events": "^1.0.0", | ||
"byte-length": "^1.0.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92274
2
862
+ Added@servie/events@^1.0.0
+ Added@servie/events@1.0.0(transitive)