publisher-subscriber-pattern
Advanced tools
Comparing version 2.0.2 to 2.0.3
@@ -0,1 +1,4 @@ | ||
# @2.0.3 [author: Katarzyna Ziomek-Zdanowicz, date: 2019.09.09] | ||
* adds Window to EmitterInstance type | ||
# @2.0.2 [author: Katarzyna Ziomek-Zdanowicz, date: 2019.09.08] | ||
@@ -2,0 +5,0 @@ * converts EventCallback to generic type so type React.Events can be used |
{ | ||
"name": "publisher-subscriber-pattern", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Publisher subscriber pattern that can be used with different event emitters including browser window", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { Subscriber } from './subscriber'; | ||
// generic type so type React.Events can be used | ||
// EventCallback is generic, thus generic type of Event can be used (e.g. type React.Events ) | ||
export type EventCallback<P = {}> = (event: P & Event) => void; | ||
@@ -8,3 +8,3 @@ | ||
export type EventData = [EventCallback, Subscriber[]]; | ||
export type EmitterInstance = Record<string | number | symbol, unknown>; | ||
export type EmitterInstance = Record<string | number | symbol, unknown> | Window; | ||
@@ -22,4 +22,10 @@ export type SubscriptionFunctions = (eventName: string, eventCallback: EventCallback) => void; | ||
if (emitterInstance instanceof Window) { | ||
return ( | ||
addListenerMethodName in emitterInstance && | ||
removeListenerMethodName in emitterInstance | ||
); | ||
} | ||
const isOfType = (value: unknown, type: 'symbol' | 'function'): boolean => typeof value === type; | ||
const addMethodName: keyof typeof emitterInstance = addListenerMethodName; | ||
@@ -26,0 +32,0 @@ const removeMethodName: keyof typeof emitterInstance = removeListenerMethodName; |
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
30382
602