publisher-subscriber-pattern
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,5 +0,9 @@ | ||
# @1.1.0 | ||
# @1.2.0 [author: Katarzyna Ziomek-Zdanowicz, date: 2019.09.07] | ||
* changes publisher's unsubscribeAll and eventSubscribersCount methods to fat arrows | ||
* adds PublisherProps type | ||
# @1.1.0 [author: Katarzyna Ziomek-Zdanowicz, date: 2019.09.07] | ||
* changes publisher's subscribe method to fat arrow | ||
# @1.0.1 | ||
# @1.0.1 [author: Katarzyna Ziomek-Zdanowicz, date: 2019.09.07] | ||
* adds babel/preset-env |
@@ -1,1 +0,1 @@ | ||
export { Publisher } from './publisher'; | ||
export { Publisher, PublisherProps } from './publisher'; |
@@ -12,3 +12,9 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "PublisherProps", { | ||
enumerable: true, | ||
get: function get() { | ||
return _publisher.PublisherProps; | ||
} | ||
}); | ||
var _publisher = require("./publisher"); |
import { EventCallback } from './subscriber'; | ||
declare type EventName = string; | ||
export declare type SubscriptionFunctions = (eventName: string, eventCallback: EventCallback) => void; | ||
export declare type PublisherProps = [unknown, SubscriptionFunctions, SubscriptionFunctions]; | ||
export declare class Publisher { | ||
@@ -8,6 +8,6 @@ private eventData; | ||
private removeEventListener; | ||
constructor(emitterInstance: unknown, addEventListener: SubscriptionFunctions, removeEventListener: SubscriptionFunctions); | ||
constructor(...[emitterInstance, addEventListener, removeEventListener]: PublisherProps); | ||
subscribe: (eventName: string, eventCallback: EventCallback, subscriberInstance?: Record<string, unknown> | undefined) => () => void; | ||
unsubscribeAll(): void; | ||
eventSubscribersCount(eventName: EventName): number; | ||
unsubscribeAll: () => void; | ||
eventSubscribersCount: (eventName: string) => number; | ||
readonly subscribersCount: number; | ||
@@ -22,2 +22,1 @@ private getEventData; | ||
} | ||
export {}; |
@@ -21,5 +21,13 @@ "use strict"; | ||
function () { | ||
function Publisher(emitterInstance, addEventListener, removeEventListener) { | ||
function Publisher() { | ||
var _this = this; | ||
for (var _len = arguments.length, _ref = new Array(_len), _key = 0; _key < _len; _key++) { | ||
_ref[_key] = arguments[_key]; | ||
} | ||
var emitterInstance = _ref[0], | ||
addEventListener = _ref[1], | ||
removeEventListener = _ref[2]; | ||
_classCallCheck(this, Publisher); | ||
@@ -44,2 +52,12 @@ | ||
_defineProperty(this, "unsubscribeAll", function () { | ||
Array.from(_this.eventData.keys()).forEach(function (eventName) { | ||
_this.unobserveEvent(eventName); | ||
}); | ||
}); | ||
_defineProperty(this, "eventSubscribersCount", function (eventName) { | ||
return _this.getSubscribers(eventName).length; | ||
}); | ||
_defineProperty(this, "buildInformSubscribers", function (eventName) { | ||
@@ -85,16 +103,2 @@ return function (event) { | ||
_createClass(Publisher, [{ | ||
key: "unsubscribeAll", | ||
value: function unsubscribeAll() { | ||
var _this2 = this; | ||
Array.from(this.eventData.keys()).forEach(function (eventName) { | ||
_this2.unobserveEvent(eventName); | ||
}); | ||
} | ||
}, { | ||
key: "eventSubscribersCount", | ||
value: function eventSubscribersCount(eventName) { | ||
return this.getSubscribers(eventName).length; | ||
} | ||
}, { | ||
key: "getEventData", | ||
@@ -101,0 +105,0 @@ value: function getEventData(eventName) { |
{ | ||
"name": "publisher-subscriber-pattern", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Publisher subscriber pattern that can be used with different event emitters including browser window", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -26,2 +26,3 @@ # About | ||
* Subscribes *eventCallback* to *eventName*, so whenever event occurs the *eventCallback* is called (with *subscriberInstance* as *this*, if provided) | ||
* Returns unsubscribe function | ||
@@ -28,0 +29,0 @@ #### unsubscribeAll |
@@ -81,2 +81,6 @@ require('chai'); | ||
expect(typeof callback1).toBe('function'); | ||
// TODO check number of subscribers | ||
// TODO przed publikacja: zmienic poprzedniego taga, uzupelnic README o przyklad instalacji, wyeksporotwac potrzebne mi typy | ||
// złapać testami to czego nie łapałam poprzednio | ||
}); | ||
@@ -83,0 +87,0 @@ |
@@ -1,1 +0,1 @@ | ||
export { Publisher } from './publisher'; | ||
export { Publisher, PublisherProps } from './publisher'; |
@@ -8,3 +8,5 @@ import { | ||
type EventData = [EventCallback, Subscriber[]]; | ||
export type SubscriptionFunctions = (eventName: string, eventCallback: EventCallback) => void; | ||
export type PublisherProps = [ unknown, SubscriptionFunctions, SubscriptionFunctions ]; | ||
@@ -15,7 +17,3 @@ export class Publisher { | ||
private removeEventListener: SubscriptionFunctions; | ||
constructor ( | ||
emitterInstance: unknown, | ||
addEventListener: SubscriptionFunctions, | ||
removeEventListener: SubscriptionFunctions | ||
) { | ||
constructor (...[ emitterInstance, addEventListener, removeEventListener ]: PublisherProps ) { | ||
this.eventData = new Map([]); | ||
@@ -37,3 +35,3 @@ | ||
public unsubscribeAll (): void { | ||
public unsubscribeAll = (): void => { | ||
Array.from(this.eventData.keys()).forEach(eventName => { | ||
@@ -44,3 +42,3 @@ this.unobserveEvent(eventName); | ||
public eventSubscribersCount (eventName: EventName): number { | ||
public eventSubscribersCount = (eventName: EventName): number => { | ||
return this.getSubscribers(eventName).length; | ||
@@ -47,0 +45,0 @@ } |
@@ -11,2 +11,3 @@ { | ||
"moduleResolution": "node", | ||
"module": "commonjs", | ||
"typeRoots": [ | ||
@@ -13,0 +14,0 @@ "./node_modules/@types", |
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
22020
466
45