Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pres/events

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pres/events - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

159

dist/index.cjs.js

@@ -8,19 +8,45 @@ 'use strict';

/**
* alias.js - event emitter for blessed
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
* https://github.com/chjj/blessed
*/
var id = 0;
function _classPrivateFieldLooseKey(name) {
return "__private_" + id++ + "_" + name;
}
function _classPrivateFieldLooseBase(receiver, privateKey) {
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
throw new TypeError("attempted to use private field on non-instance");
}
return receiver;
}
const SP = ' ';
const slice = Array.prototype.slice;
var _events = _classPrivateFieldLooseKey("events");
var _max = _classPrivateFieldLooseKey("max");
var _emit = _classPrivateFieldLooseKey("emit");
class EventEmitter {
/**
* EventEmitter
*/
constructor() {
this.on = this.addListener;
this.off = this.removeListener;
if (!this._events) this._events = {}; // console.log('>>> [EventEmitter is constructed]')
Object.defineProperty(this, _emit, {
value: _emit2
});
Object.defineProperty(this, _events, {
writable: true,
value: {}
});
Object.defineProperty(this, _max, {
writable: true,
value: Infinity
});
this.addListener = this.on;
this.removeListener = this.off;
this._emit = _classPrivateFieldLooseBase(this, _emit)[_emit];
}
build() {
static build() {
return new EventEmitter();

@@ -30,27 +56,32 @@ }

setMaxListeners(n) {
this._maxListeners = n;
_classPrivateFieldLooseBase(this, _max)[_max] = n;
}
addListener(type, listener) {
if (!this._events[type]) {
this._events[type] = listener;
} else if (typeof this._events[type] === enumDataTypes.FUN) {
this._events[type] = [this._events[type], listener];
get events() {
return _classPrivateFieldLooseBase(this, _events)[_events];
}
on(type, listener) {
if (!_classPrivateFieldLooseBase(this, _events)[_events][type]) {
_classPrivateFieldLooseBase(this, _events)[_events][type] = listener;
} else if (typeof _classPrivateFieldLooseBase(this, _events)[_events][type] === enumDataTypes.FUN) {
_classPrivateFieldLooseBase(this, _events)[_events][type] = [_classPrivateFieldLooseBase(this, _events)[_events][type], listener];
} else {
this._events[type].push(listener);
_classPrivateFieldLooseBase(this, _events)[_events][type].push(listener);
}
this._emit(enumEvents.NEW_LISTENER, [type, listener]);
_classPrivateFieldLooseBase(this, _emit)[_emit](enumEvents.NEW_LISTENER, [type, listener]);
}
removeListener(type, listener) {
const handler = this._events[type];
if (!handler) return;
off(type, listener) {
const handler = _classPrivateFieldLooseBase(this, _events)[_events][type];
if (!handler) return void 0;
if (typeof handler === enumDataTypes.FUN || handler.length === 1) {
delete this._events[type];
delete _classPrivateFieldLooseBase(this, _events)[_events][type];
this._emit(enumEvents.REMOVE_LISTENER, [type, listener]);
_classPrivateFieldLooseBase(this, _emit)[_emit](enumEvents.REMOVE_LISTENER, [type, listener]);
return;
return void 0;
}

@@ -62,5 +93,5 @@

this._emit(enumEvents.REMOVE_LISTENER, [type, listener]);
_classPrivateFieldLooseBase(this, _emit)[_emit](enumEvents.REMOVE_LISTENER, [type, listener]);
return;
return void 0;
}

@@ -71,3 +102,3 @@ }

removeAllListeners(type) {
type ? delete this._events[type] : this._events = {};
type ? delete _classPrivateFieldLooseBase(this, _events)[_events][type] : _classPrivateFieldLooseBase(this, _events)[_events] = {};
}

@@ -79,4 +110,3 @@

function on() {
self.removeListener(type, on);
return listener.apply(self, arguments);
return self.removeListener(type, on), listener.apply(self, arguments);
}

@@ -89,40 +119,19 @@

listeners(type) {
return typeof this._events[type] === enumDataTypes.FUN ? [this._events[type]] : this._events[type] || [];
return typeof _classPrivateFieldLooseBase(this, _events)[_events][type] === enumDataTypes.FUN ? [_classPrivateFieldLooseBase(this, _events)[_events][type]] : _classPrivateFieldLooseBase(this, _events)[_events][type] ?? [];
}
_emit(type, args) {
const handler = this._events[type];
let result;
emit(type, ...args) {
let node = this;
if (!handler) {
if (type === enumEvents.ERROR) throw new args[0]();else return void 0;
}
_classPrivateFieldLooseBase(this, _emit)[_emit](enumEvents.EVENT, slice.call(arguments));
if (typeof handler === enumDataTypes.FUN) return handler.apply(this, args);
if (this.type === 'screen') return _classPrivateFieldLooseBase(this, _emit)[_emit](type, args);
if (_classPrivateFieldLooseBase(this, _emit)[_emit](type, args) === false) return false;
type = 'element' + SP + type;
args.unshift(this); // const elementArgs = [ node ].concat(args)
for (let i = 0; i < handler.length; i++) if (handler[i].apply(this, args) === false) result = false;
return result !== false;
}
emit(type) {
const args = slice.call(arguments, 1),
params = slice.call(arguments);
let el = this;
this._emit(enumEvents.EVENT, params);
if (this.type === 'screen') return this._emit(type, args);
if (this._emit(type, args) === false) return false;
type = 'element ' + type;
args.unshift(this); // `element` prefix
// params = [type].concat(args);
// no `element` prefix
// params.splice(1, 0, this);
do {
// el._emit(EVENT, params);
if (!el._events[type]) continue;
if (el._emit(type, args) === false) return false;
} while (el = el.sup);
if (!node.events[type]) continue;
if (node._emit(type, args) === false) return false;
} while (node = node.sup);

@@ -136,3 +145,3 @@ return true;

// it gives us domain support as well.
// Node.prototype._emit = Node.prototype.emit;
// Node.prototype.#emit = Node.prototype.emit;
// Node.prototype.emit = function(type) {

@@ -142,6 +151,6 @@ // var args, el;

// if (this.type === 'screen') {
// return this._emit.apply(this, arguments);
// return this.#emit.apply(this, arguments);
// }
//
// this._emit.apply(this, arguments);
// this.#emit.apply(this, arguments);
// if (this._bubbleStopped) return false;

@@ -157,4 +166,4 @@ //

// do {
// if (!el._events || !el._events[type]) continue;
// el._emit.apply(el, args);
// if (!el.#events || !el.#events[type]) continue;
// el.#emit.apply(el, args);
// if (this._bubbleStopped) return false;

@@ -178,2 +187,16 @@ // } while ((el = el.sup));

function _emit2(type, args) {
const handler = _classPrivateFieldLooseBase(this, _events)[_events][type];
let result;
if (!handler) return type === enumEvents.ERROR ? function (e) {
throw e;
}(new args[0]()) : void 0;
if (typeof handler === enumDataTypes.FUN) return handler.apply(this, args);
for (let i = 0; i < handler.length; i++) if (handler[i].apply(this, args) === false) result = false;
return result !== false;
}
exports.EventEmitter = EventEmitter;

@@ -1,21 +0,47 @@

import { NEW_LISTENER, REMOVE_LISTENER, ERROR, EVENT } from '@pres/enum-events';
import { NEW_LISTENER, REMOVE_LISTENER, EVENT, ERROR } from '@pres/enum-events';
import { FUN } from '@typen/enum-data-types';
/**
* alias.js - event emitter for blessed
* Copyright (c) 2013-2015, Christopher Jeffrey and contributors (MIT License).
* https://github.com/chjj/blessed
*/
var id = 0;
function _classPrivateFieldLooseKey(name) {
return "__private_" + id++ + "_" + name;
}
function _classPrivateFieldLooseBase(receiver, privateKey) {
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
throw new TypeError("attempted to use private field on non-instance");
}
return receiver;
}
const SP = ' ';
const slice = Array.prototype.slice;
var _events = _classPrivateFieldLooseKey("events");
var _max = _classPrivateFieldLooseKey("max");
var _emit = _classPrivateFieldLooseKey("emit");
class EventEmitter {
/**
* EventEmitter
*/
constructor() {
this.on = this.addListener;
this.off = this.removeListener;
if (!this._events) this._events = {}; // console.log('>>> [EventEmitter is constructed]')
Object.defineProperty(this, _emit, {
value: _emit2
});
Object.defineProperty(this, _events, {
writable: true,
value: {}
});
Object.defineProperty(this, _max, {
writable: true,
value: Infinity
});
this.addListener = this.on;
this.removeListener = this.off;
this._emit = _classPrivateFieldLooseBase(this, _emit)[_emit];
}
build() {
static build() {
return new EventEmitter();

@@ -25,27 +51,32 @@ }

setMaxListeners(n) {
this._maxListeners = n;
_classPrivateFieldLooseBase(this, _max)[_max] = n;
}
addListener(type, listener) {
if (!this._events[type]) {
this._events[type] = listener;
} else if (typeof this._events[type] === FUN) {
this._events[type] = [this._events[type], listener];
get events() {
return _classPrivateFieldLooseBase(this, _events)[_events];
}
on(type, listener) {
if (!_classPrivateFieldLooseBase(this, _events)[_events][type]) {
_classPrivateFieldLooseBase(this, _events)[_events][type] = listener;
} else if (typeof _classPrivateFieldLooseBase(this, _events)[_events][type] === FUN) {
_classPrivateFieldLooseBase(this, _events)[_events][type] = [_classPrivateFieldLooseBase(this, _events)[_events][type], listener];
} else {
this._events[type].push(listener);
_classPrivateFieldLooseBase(this, _events)[_events][type].push(listener);
}
this._emit(NEW_LISTENER, [type, listener]);
_classPrivateFieldLooseBase(this, _emit)[_emit](NEW_LISTENER, [type, listener]);
}
removeListener(type, listener) {
const handler = this._events[type];
if (!handler) return;
off(type, listener) {
const handler = _classPrivateFieldLooseBase(this, _events)[_events][type];
if (!handler) return void 0;
if (typeof handler === FUN || handler.length === 1) {
delete this._events[type];
delete _classPrivateFieldLooseBase(this, _events)[_events][type];
this._emit(REMOVE_LISTENER, [type, listener]);
_classPrivateFieldLooseBase(this, _emit)[_emit](REMOVE_LISTENER, [type, listener]);
return;
return void 0;
}

@@ -57,5 +88,5 @@

this._emit(REMOVE_LISTENER, [type, listener]);
_classPrivateFieldLooseBase(this, _emit)[_emit](REMOVE_LISTENER, [type, listener]);
return;
return void 0;
}

@@ -66,3 +97,3 @@ }

removeAllListeners(type) {
type ? delete this._events[type] : this._events = {};
type ? delete _classPrivateFieldLooseBase(this, _events)[_events][type] : _classPrivateFieldLooseBase(this, _events)[_events] = {};
}

@@ -74,4 +105,3 @@

function on() {
self.removeListener(type, on);
return listener.apply(self, arguments);
return self.removeListener(type, on), listener.apply(self, arguments);
}

@@ -84,40 +114,19 @@

listeners(type) {
return typeof this._events[type] === FUN ? [this._events[type]] : this._events[type] || [];
return typeof _classPrivateFieldLooseBase(this, _events)[_events][type] === FUN ? [_classPrivateFieldLooseBase(this, _events)[_events][type]] : _classPrivateFieldLooseBase(this, _events)[_events][type] ?? [];
}
_emit(type, args) {
const handler = this._events[type];
let result;
emit(type, ...args) {
let node = this;
if (!handler) {
if (type === ERROR) throw new args[0]();else return void 0;
}
_classPrivateFieldLooseBase(this, _emit)[_emit](EVENT, slice.call(arguments));
if (typeof handler === FUN) return handler.apply(this, args);
if (this.type === 'screen') return _classPrivateFieldLooseBase(this, _emit)[_emit](type, args);
if (_classPrivateFieldLooseBase(this, _emit)[_emit](type, args) === false) return false;
type = 'element' + SP + type;
args.unshift(this); // const elementArgs = [ node ].concat(args)
for (let i = 0; i < handler.length; i++) if (handler[i].apply(this, args) === false) result = false;
return result !== false;
}
emit(type) {
const args = slice.call(arguments, 1),
params = slice.call(arguments);
let el = this;
this._emit(EVENT, params);
if (this.type === 'screen') return this._emit(type, args);
if (this._emit(type, args) === false) return false;
type = 'element ' + type;
args.unshift(this); // `element` prefix
// params = [type].concat(args);
// no `element` prefix
// params.splice(1, 0, this);
do {
// el._emit(EVENT, params);
if (!el._events[type]) continue;
if (el._emit(type, args) === false) return false;
} while (el = el.sup);
if (!node.events[type]) continue;
if (node._emit(type, args) === false) return false;
} while (node = node.sup);

@@ -131,3 +140,3 @@ return true;

// it gives us domain support as well.
// Node.prototype._emit = Node.prototype.emit;
// Node.prototype.#emit = Node.prototype.emit;
// Node.prototype.emit = function(type) {

@@ -137,6 +146,6 @@ // var args, el;

// if (this.type === 'screen') {
// return this._emit.apply(this, arguments);
// return this.#emit.apply(this, arguments);
// }
//
// this._emit.apply(this, arguments);
// this.#emit.apply(this, arguments);
// if (this._bubbleStopped) return false;

@@ -152,4 +161,4 @@ //

// do {
// if (!el._events || !el._events[type]) continue;
// el._emit.apply(el, args);
// if (!el.#events || !el.#events[type]) continue;
// el.#emit.apply(el, args);
// if (this._bubbleStopped) return false;

@@ -173,2 +182,16 @@ // } while ((el = el.sup));

function _emit2(type, args) {
const handler = _classPrivateFieldLooseBase(this, _events)[_events][type];
let result;
if (!handler) return type === ERROR ? function (e) {
throw e;
}(new args[0]()) : void 0;
if (typeof handler === FUN) return handler.apply(this, args);
for (let i = 0; i < handler.length; i++) if (handler[i].apply(this, args) === false) result = false;
return result !== false;
}
export { EventEmitter };
{
"name": "@pres/events",
"version": "0.1.8",
"version": "0.1.9",
"description": "EventEmitter for pres",

@@ -18,3 +18,3 @@ "main": "dist/index.cjs.js",

"dependencies": {
"@pres/enum-events": "^0.1.8",
"@pres/enum-events": "^0.1.9",
"@typen/enum-data-types": "^0.1.16"

@@ -42,3 +42,3 @@ },

"homepage": "https://github.com/hoyeungw/pres/cluster#readme",
"gitHead": "3c4e4766e2637016db118dfc135091a5414c0c1c"
"gitHead": "0ea4c89e8d3c8088ed8143b483d1357687c8890f"
}
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