@lite-v3/common-helpers
Advanced tools
Comparing version 0.1.1 to 0.1.2
/** | ||
* This is a simpler version of `Record<T, U>` which do not rely | ||
* on index type checks to determine whether a type is an object | ||
* or not. Unlike the `object` type, this has an additional checks | ||
* to exclude `Array<T>`, and are intended to be used in an `extends` clause. | ||
*/ | ||
declare type AnyRecord<T> = any[] extends T ? never : object; | ||
/** | ||
* | ||
@@ -29,3 +36,2 @@ * @see https://github.com/developit/mitt | ||
*/ | ||
export declare type EventType = string | symbol; | ||
export declare type Handler<T = unknown> = (event: T) => void; | ||
@@ -35,4 +41,4 @@ export declare type WildcardHandler<T = Record<string, unknown>> = (type: keyof T, event: T[keyof T]) => void; | ||
export declare type WildCardEventHandlerList<T = Record<string, unknown>> = Array<WildcardHandler<T>>; | ||
export declare type EventHandlerMap<Events extends Record<EventType, unknown>> = Map<keyof Events | '*', EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>>; | ||
export interface Emitter<Events extends Record<EventType, unknown>> { | ||
export declare type EventHandlerMap<Events extends AnyRecord<Events>> = Map<keyof Events | '*', EventHandlerList<Events[keyof Events]> | WildCardEventHandlerList<Events>>; | ||
export interface Emitter<Events extends AnyRecord<Events>> { | ||
all: EventHandlerMap<Events>; | ||
@@ -46,3 +52,3 @@ on<Key extends keyof Events>(type: Key, handler: Handler<Events[Key]>): void; | ||
} | ||
declare function mitt<Events extends Record<EventType, unknown>>(all?: EventHandlerMap<Events>): Emitter<Events>; | ||
declare function mitt<Events extends AnyRecord<Events>>(all?: EventHandlerMap<Events>): Emitter<Events>; | ||
export default mitt; |
@@ -57,2 +57,7 @@ "use strict"; | ||
handlers.slice().forEach(function(handler) { | ||
/** | ||
* This is valid since, although `evt` may be optional, from our | ||
* function overload it will map only to `undefined` while kept | ||
* enforcing the other types to be required. | ||
*/ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
handler(evt); | ||
@@ -64,2 +69,7 @@ }); | ||
handlers.slice().forEach(function(handler) { | ||
/** | ||
* This is valid since, although `evt` may be optional, from our | ||
* function overload it will map only to `undefined` while kept | ||
* enforcing the other types to be required. | ||
*/ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
handler(type, evt); | ||
@@ -66,0 +76,0 @@ }); |
{ | ||
"name": "@lite-v3/common-helpers", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Public common helpers for Tokopedia Web", | ||
@@ -5,0 +5,0 @@ "repository": { |
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
79232
2270