Socket
Socket
Sign inDemoInstall

event-pubsub

Package Overview
Dependencies
Maintainers
2
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.2.4 to 4.3.0

32

es5.js

@@ -7,6 +7,7 @@ 'use strict';

this.subscribe=this.on=on;
this.once=once;
this.unSubscribe=this.off=off;
this.emit$=emit$;
function on(type,handler){
function on(type,handler,once){
if(!handler){

@@ -20,2 +21,5 @@ throw new ReferenceError('handler not defined.');

if(once){
handler._once_ = once;
}
this._events_[type].push(handler);

@@ -25,2 +29,6 @@ return this;

function once(type,handler){
return this.on(type, handler, true);
}
function off(type,handler){

@@ -40,3 +48,3 @@ if(!this._events_[type]){

const handlers=this._events_[type];
var handlers=this._events_[type];

@@ -65,8 +73,20 @@ while(handlers.includes(handler)){

const handlers=this._events_[type];
var handlers=this._events_[type];
var onceHandled=[];
for(let handler of handlers){
for(var i in handlers){
var handler=handlers[i];
handler.apply(this, arguments);
if(handler._once_){
onceHandled.push(handler);
}
}
for(var i in onceHandled){
this.off(
type,
onceHandled[i]
);
}
return this;

@@ -80,3 +100,3 @@ }

const catchAll=this._events_['*'];
var catchAll=this._events_['*'];

@@ -86,3 +106,3 @@ args.shift=Array.prototype.shift;

for(let handler of catchAll){
for(var handler of catchAll){
handler.apply(this, args);

@@ -89,0 +109,0 @@ }

@@ -11,3 +11,3 @@ 'use strict';

on( type, handler ) {
on( type, handler, once ) {
if ( !handler ) {

@@ -21,2 +21,6 @@ throw new ReferenceError( 'handler not defined.' );

if(once){
handler._once_ = once;
}
this._events_[ type ].push( handler );

@@ -26,2 +30,6 @@ return this;

once( type, handler ) {
return this.on( type, handler, true );
}
off( type, handler ) {

@@ -63,7 +71,15 @@ if ( !this._events_[ type ] ) {

const handlers = this._events_[ type ];
const onceHandled=[];
for ( let handler of handlers ) {
handler.apply( this, args );
if(handler._once_){
onceHandled.push(handler);
}
}
for(let handler of onceHandled){
this.off(type,handler);
}
return this.emit$( type, ...args );

@@ -70,0 +86,0 @@ }

149

event-pubsub-browser-es5.js
'use strict';
window.EventPubSub=function EventPubSub() {
this._events_={};
this.publish=this.trigger=this.emit=emit;
this.subscribe=this.on=on;
this.unSubscribe=this.off=off;
this.emit$=emit$;
this._events_={};
this.publish=this.trigger=this.emit=emit;
this.subscribe=this.on=on;
this.once=once;
this.unSubscribe=this.off=off;
this.emit$=emit$;
function on(type,handler){
if(!handler){
const err=new ReferenceError('handler not defined.');
throw(err);
}
function on(type,handler,once){
if(!handler){
throw new ReferenceError('handler not defined.');
}
if(!this._events_[type]){
this._events_[type]=[];
}
if(!this._events_[type]){
this._events_[type]=[];
}
this._events_[type].push(handler);
return this;
}
if(once){
handler._once_ = once;
}
this._events_[type].push(handler);
return this;
}
function off(type,handler){
if(!this._events_[type]){
return this;
}
function once(type,handler){
return this.on(type, handler, true);
}
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;
}
function off(type,handler){
if(!this._events_[type]){
return this;
}
if(handler=='*'){
delete this._events_[type];
return this;
}
if(!handler){
throw new ReferenceError('handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler');
}
const handlers=this._events_[type];
if(handler=='*'){
delete this._events_[type];
return this;
}
while(handlers.includes(handler)){
handlers.splice(
handlers.indexOf(handler),
1
);
}
var handlers=this._events_[type];
if(handlers.length<1){
delete this._events_[type];
}
while(handlers.includes(handler)){
handlers.splice(
handlers.indexOf(handler),
1
);
}
return this;
}
if(handlers.length<1){
delete this._events_[type];
}
function emit(type){
this.emit$.apply(this, arguments);
if(!this._events_[type]){
return this;
}
return this;
}
arguments.splice=Array.prototype.splice;
arguments.splice(0,1);
function emit(type){
this.emit$.apply(this, arguments);
if(!this._events_[type]){
return this;
}
arguments.splice=Array.prototype.splice;
arguments.splice(0,1);
const handlers=this._events_[type];
var handlers=this._events_[type];
var onceHandled=[];
for(let handler of handlers){
handler.apply(this, arguments);
}
for(var i in handlers){
var handler=handlers[i];
handler.apply(this, arguments);
if(handler._once_){
onceHandled.push(handler);
}
}
return this;
}
for(var i in onceHandled){
this.off(
type,
onceHandled[i]
);
}
function emit$(type, args){
if(!this._events_['*']){
return this;
}
return this;
}
const catchAll=this._events_['*'];
function emit$(type, args){
if(!this._events_['*']){
return this;
}
args.shift=Array.prototype.shift;
args.shift(type);
var catchAll=this._events_['*'];
for(let handler of catchAll){
handler.apply(this, args);
}
args.shift=Array.prototype.shift;
args.shift(type);
return this;
}
for(var handler of catchAll){
handler.apply(this, args);
}
return this;
return this;
}
return this;
}

@@ -92,0 +109,0 @@

'use strict';
window.EventPubSub=class EventPubSub {
constructor(scope){
this._events_={};
this.publish=this.trigger=this.emit;
this.subscribe=this.on;
this.unSubscribe=this.off;
}
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);
}
on( type, handler, once ) {
if ( !handler ) {
throw new ReferenceError( 'handler not defined.' );
}
if(!this._events_[type]){
this._events_[type]=[];
}
if ( !this._events_[ type ] ) {
this._events_[ type ] = [];
}
this._events_[type].push(handler);
return this;
}
if(once){
handler._once_ = once;
}
off(type,handler){
if(!this._events_[type]){
return this;
}
this._events_[ type ].push( handler );
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;
}
once( type, handler ) {
return this.on( type, handler, true );
}
if(handler=='*'){
delete this._events_[type];
return this;
}
off( type, handler ) {
if ( !this._events_[ type ] ) {
return this;
}
const handlers=this._events_[type];
if ( !handler ) {
throw new ReferenceError( 'handler not defined. if you wish to remove all handlers from the event please pass "*" as the handler' );
}
while(handlers.includes(handler)){
handlers.splice(
handlers.indexOf(handler),
1
);
}
if ( handler == '*' ) {
delete this._events_[ type ];
return this;
}
if(handlers.length<1){
delete this._events_[type];
}
const handlers = this._events_[ type ];
return this;
}
while ( handlers.includes( handler ) ) {
handlers.splice(
handlers.indexOf( handler ),
1
);
}
emit(type,...args){
if(!this._events_[type]){
return this.emit$(type,...args);
}
if ( handlers.length < 1 ) {
delete this._events_[ type ];
}
const handlers=this._events_[type];
return this;
}
for(let handler of handlers){
handler.apply(this, args);
}
emit( type, ...args ) {
if ( !this._events_[ type ] ) {
return this.emit$( type, ...args );
}
return this.emit$(type,...args);
}
const handlers = this._events_[ type ];
const onceHandled=[];
emit$(type,...args){
if(!this._events_['*']){
return this;
}
for ( let handler of handlers ) {
handler.apply( this, args );
if(handler._once_){
onceHandled.push(handler);
}
}
const catchAll=this._events_['*'];
for(let handler of onceHandled){
this.off(type,handler);
}
for(let handler of catchAll){
handler.call(this, type, args);
}
return this.emit$( type, ...args );
}
return this;
}
emit$( type, ...args ) {
if ( !this._events_[ '*' ] ) {
return this;
}
const catchAll = this._events_[ '*' ];
for ( let handler of catchAll ) {
handler.call( this, type, ...args );
}
return this;
}
}

@@ -84,0 +98,0 @@

{
"name": "event-pubsub",
"version": "4.2.4",
"version": "4.3.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",

@@ -44,4 +44,5 @@ # Event PubSub

|------|---------|-----------|
|subscribe|type (string), handler(function)|will bind the `handler` function to the the `type` event. Just like `addEventListener` in the browser|
|subscribe|type (string), handler(function), once (bool/optional)|will bind the `handler` function to the the `type` event. Just like `addEventListener` in the browser. If once is set to true the hander will be removed after being called once.|
|on|same as above|same as above|
|once|type (string), handler(function)| will bind the `handler` function to the the `type` event and unbind it after ***one*** execution. Just like `addEventListener` in the browser withe the `once` option set|
|unSubscribe|type (string), handler(function or *)|will ***un***bind the `handler` function from the the `type` event. If the `handler` is `*`, all handlers for the event type will be removed. Just like `removeEventListener` in the browser, but also can remove all event handlers for the type.|

@@ -48,0 +49,0 @@ |off|same as above|same as above|

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