publisher-subscriber-pattern
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -0,2 +1,5 @@ | ||
# @1.1.0 | ||
* changes publisher's subscribe method to fat arrow | ||
# @1.0.1 | ||
* adds babel/preset-env | ||
* adds babel/preset-env |
@@ -9,3 +9,3 @@ import { EventCallback } from './subscriber'; | ||
constructor(emitterInstance: unknown, addEventListener: SubscriptionFunctions, removeEventListener: SubscriptionFunctions); | ||
subscribe(eventName: EventName, eventCallback: EventCallback, subscriberInstance?: Record<string, unknown>): () => void; | ||
subscribe: (eventName: string, eventCallback: EventCallback, subscriberInstance?: Record<string, unknown> | undefined) => () => void; | ||
unsubscribeAll(): void; | ||
@@ -12,0 +12,0 @@ eventSubscribersCount(eventName: EventName): number; |
@@ -32,2 +32,13 @@ "use strict"; | ||
_defineProperty(this, "subscribe", function (eventName, eventCallback, subscriberInstance) { | ||
var eventData = _this.getEventData(eventName); | ||
var subscriber = new _subscriber.Subscriber(eventCallback, subscriberInstance); | ||
eventData[1].push(subscriber); | ||
_this.observeEvent(eventName); | ||
return _this.unsubscribe(eventName, subscriber); | ||
}); | ||
_defineProperty(this, "buildInformSubscribers", function (eventName) { | ||
@@ -73,11 +84,2 @@ return function (event) { | ||
_createClass(Publisher, [{ | ||
key: "subscribe", | ||
value: function subscribe(eventName, eventCallback, subscriberInstance) { | ||
var eventData = this.getEventData(eventName); | ||
var subscriber = new _subscriber.Subscriber(eventCallback, subscriberInstance); | ||
eventData[1].push(subscriber); | ||
this.observeEvent(eventName); | ||
return this.unsubscribe(eventName, subscriber); | ||
} | ||
}, { | ||
key: "unsubscribeAll", | ||
@@ -84,0 +86,0 @@ value: function unsubscribeAll() { |
{ | ||
"name": "publisher-subscriber-pattern", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Publisher subscriber pattern that can be used with different event emitters including browser window", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -8,7 +8,7 @@ # About | ||
## **Publisher** | ||
* Takes arguments: *emitterInstance*, *addEventListener* and *removeEventListener* | ||
* Exposes methods: *subscribe*, *unsubscribeAll* and *eventSubscribersCount* | ||
* Has property: *subscribersCount* | ||
* Parameters: *emitterInstance*, *addEventListener*, *removeEventListener* | ||
* Methods: *subscribe*, *unsubscribeAll*, *eventSubscribersCount* | ||
* Properties: *subscribersCount* | ||
### Arguments | ||
### Parameters | ||
@@ -18,4 +18,4 @@ #### emitterInstance | ||
#### addEventListener and removeEventListener | ||
* Methods exposed by *emitterInstance* which add and remove event listeners, respectively | ||
#### addEventListener, removeEventListener | ||
* Methods exposed by *emitterInstance* which *add* and *remove* event listeners, respectively | ||
@@ -25,4 +25,4 @@ ### Methods | ||
#### subscribe | ||
* Requires two arguments: *eventName* and *eventCallback* | ||
* Accepts optional argument: *subscriberInstance* that will be bound to *eventCallback* as *this* | ||
* Required parameters: *eventName*, *eventCallback* | ||
* Optional parameter: *subscriberInstance* that will be bound to *eventCallback* as *this* | ||
* Subscribes *eventCallback* to *eventName*, so whenever event occurs the *eventCallback* is called (with *subscriberInstance* as *this*, if provided) | ||
@@ -35,3 +35,3 @@ | ||
#### eventSubscriberCount | ||
* Requires argument: *eventName* | ||
* Required parameter: *eventName* | ||
* Returns number of *eventCallbacks* subscribed to the *evenName* | ||
@@ -38,0 +38,0 @@ |
@@ -25,3 +25,3 @@ import { | ||
public subscribe (eventName: EventName, eventCallback: EventCallback, subscriberInstance?: Record<string, unknown>): () => void { | ||
public subscribe = (eventName: EventName, eventCallback: EventCallback, subscriberInstance?: Record<string, unknown>): () => void => { | ||
const eventData = this.getEventData(eventName); | ||
@@ -28,0 +28,0 @@ const subscriber = new Subscriber(eventCallback, subscriberInstance); |
{ | ||
"extends": "./tsconfig", | ||
"compilerOptions": { | ||
"target": "es5", | ||
"noImplicitAny": true, | ||
"allowSyntheticDefaultImports": true, | ||
"baseUrl": ".", | ||
"outDir": "dist", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"./src/**/*", | ||
], | ||
"lib": [ "dom", "es2015", "es2017" ] | ||
"noEmit": false | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"spec", | ||
"*.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
21063
459