Socket
Socket
Sign inDemoInstall

event-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-pubsub - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

es6.js

79

event-pubsub.js
'use strict';
class EventPubSub {
constructor(scope){
this._events_={};
this.publish=this.trigger=this.emit;
this.subscribe=this.on;
this.unSubscribe=this.off;
}
on(type,handler){
if(!handler){
const err=new ReferenceError('handler not defined.');
throw(err);
}
if(!this._events_[type]){
this._events_[type]=[];
}
this._events_[type].push(handler);
return this;
}
off(type,handler){
if(!this._events_[type]){
return this;
}
if(!handler){
var err=new ReferenceError('handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler');
throw err;
}
if(handler=='*'){
delete this._events_[type];
return this;
}
const handlers=this._events_[type];
while(handlers.includes(handler)){
handlers.splice(
handlers.indexOf(handler),
1
);
}
if(handlers.length<1){
delete this._events_[type];
}
return this;
}
emit(type,...args){
if(!this._events_[type]){
return;
}
const handlers=this._events_[type];
for(let handler of handlers){
handler.apply(this, args);
}
if(!this._events_['*']){
return this;
}
const catchAll=this._events_['*'];
for(let handler of catchAll){
handler.apply(this, args);
}
return this;
}
let EventPubSub = require('./es5');
if(process.version[1]>4){
EventPubSub = require('./es6');
}
module.exports=EventPubSub;
{
"name": "event-pubsub",
"version": "4.0.0",
"version": "4.1.0",
"description": "Super light and fast Extensible PubSub events and EventEmitters for Node and the browser with support for ES6 by default, and ES5 versions for older verions of node and older IE/Safari versions. Easy for any developer level. No frills, just high speed pubsub events!",

@@ -5,0 +5,0 @@ "main": "event-pubsub.js",

@@ -67,2 +67,3 @@ # Event PubSub

// ES5/ES6 now automatically chosen based on node version
const Events = new require('event-pubsub');

@@ -196,3 +197,6 @@ const events=new Events;

// ES5/ES6 now automatically chosen based on node version
const Events = require('event-pubsub');
// manually include es6
// const Events = require('event-pubsub/es6');

@@ -244,2 +248,3 @@ class Book extends Events{

// manually include es5
const Events = require('event-pubsub/es5.js');

@@ -246,0 +251,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc