@for-fun/event-emitter
Advanced tools
Comparing version 0.1.2 to 0.1.3
/*! | ||
* @for-fun/event-emitter v0.1.2 (https://github.com/wmzy/event-emitter) | ||
* @for-fun/event-emitter v0.1.3 (https://github.com/wmzy/event-emitter) | ||
* Copyright (c) 2019-present wmzy | ||
@@ -4,0 +4,0 @@ * Licensed under MIT (https://github.com/wmzy/event-emitter/blob/master/LICENSE) |
@@ -1,24 +0,44 @@ | ||
export type Handler = (...args: unknown[]) => void; | ||
export const errorEvent: symbol; | ||
export type EventType = string | symbol; | ||
declare const s: unique symbol; | ||
type S = typeof s; | ||
type ET = [EventType, any[]] | EventType; | ||
type Key<T extends ET> = | ||
| Extract<T, [EventType, any[]]>[0] | ||
| Extract<T, EventType>; | ||
type Param<T extends ET, K extends Key<T>> = K extends Extract<T, EventType> | ||
? [] | ||
: Extract<T, [K, any[]]>[1]; | ||
export type EventEmitter<T extends ET> = { | ||
[s]: { | ||
[key in Key<T>]: Param<T, key>; | ||
} | ||
}; | ||
export type Handler<P extends any[]> = (...args: P) => void; | ||
export type ErrorHandler = (err: Error) => void; | ||
export type OffFunction = () => void; | ||
export type EventEmitter<K> = Map<K, Set<Handler>>; | ||
export const errorEvent: Symbol; | ||
export function create<K>(): EventEmitter<K>; | ||
export function emit<K>(ee: EventEmitter<K>, key: K, ...args: unknown[]): void; | ||
export function emitError<K>(ee: EventEmitter<K>, err: Error): void; | ||
export function on<K>(ee: EventEmitter<K>, key: K, handler: Handler): OffFunction; | ||
export function onError<K>(ee: EventEmitter<K>, handler: ErrorHandler): OffFunction; | ||
export function once<K>(ee: EventEmitter<K>, key: K, handler: Handler): OffFunction; | ||
export function onceError<K>(ee: EventEmitter<K>, handler: ErrorHandler): OffFunction; | ||
export function create<T extends ET>(): EventEmitter<T>; | ||
export function emit<E extends EventEmitter<ET>, K extends keyof E[S]>(ee: E, key: K, ...args: E[S][K]): void; | ||
export function emitError(ee: EventEmitter<ET>, err: Error): void; | ||
export function on<E extends EventEmitter<ET>, K extends keyof E[S]>(ee: E, key: K, handler: Handler<E[S][K]>): OffFunction; | ||
export function onError(ee: EventEmitter<ET>, handler: ErrorHandler): OffFunction; | ||
export function once<E extends EventEmitter<ET>, K extends keyof E[S]>(ee: E, key: K, handler: Handler<E[S][K]>): OffFunction; | ||
export function onceError(ee: EventEmitter<ET>, handler: ErrorHandler): OffFunction; | ||
export function bindContext(context: any): (func: Function) => Function; | ||
export function createAndBind<K>(): { | ||
emit(key: K, ...args: unknown[]): void; | ||
export function createAndBind<T extends ET>(): { | ||
emit<K extends keyof EventEmitter<T>[S]>(key: K, ...args: EventEmitter<T>[S][K]): void; | ||
emitError(err: Error): void; | ||
on(key: K, handler: Handler): OffFunction; | ||
on<K extends keyof EventEmitter<T>[S]>(key: K, handler: Handler<EventEmitter<T>[S][K]>): OffFunction; | ||
onError(handler: ErrorHandler): OffFunction; | ||
once(key: K, handler: Handler): OffFunction; | ||
once<K extends keyof EventEmitter<T>[S]>(key: K, handler: Handler<EventEmitter<T>[S][K]>): OffFunction; | ||
onceError(handler: ErrorHandler): OffFunction; | ||
}; |
{ | ||
"name": "@for-fun/event-emitter", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "event-emitter", | ||
@@ -5,0 +5,0 @@ "main": "dist/event-emitter.cjs.js", |
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
26350
268