Socket
Socket
Sign inDemoInstall

@stoplight/emitter

Package Overview
Dependencies
1
Maintainers
5
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.43 to 0.0.44-alpha.0

139

lib/emitter.js

@@ -1,6 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NOOP = function () {
export const NOOP = () => {
return {
dispose: function () {
dispose: () => {
// nada

@@ -10,8 +8,4 @@ },

};
var CallbackList = /** @class */ (function () {
function CallbackList() {
}
CallbackList.prototype.add = function (callback, context, bucket) {
var _this = this;
if (context === void 0) { context = null; }
class CallbackList {
add(callback, context = null, bucket) {
if (!this._callbacks) {

@@ -24,12 +18,11 @@ this._callbacks = [];

if (Array.isArray(bucket)) {
bucket.push({ dispose: function () { return _this.remove(callback, context); } });
bucket.push({ dispose: () => this.remove(callback, context) });
}
};
CallbackList.prototype.remove = function (callback, context) {
if (context === void 0) { context = null; }
}
remove(callback, context = null) {
if (!this._callbacks) {
return;
}
var foundCallbackWithDifferentContext = false;
for (var i = 0, len = this._callbacks.length; i < len; i++) {
let foundCallbackWithDifferentContext = false;
for (let i = 0, len = this._callbacks.length; i < len; i++) {
if (this._callbacks[i] === callback) {

@@ -50,15 +43,11 @@ if (this._contexts[i] === context) {

}
};
CallbackList.prototype.invoke = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
}
invoke(...args) {
if (!this._callbacks) {
return [];
}
var ret = [];
var callbacks = this._callbacks.slice(0);
var contexts = this._contexts.slice(0);
for (var i = 0, len = callbacks.length; i < len; i++) {
const ret = [];
const callbacks = this._callbacks.slice(0);
const contexts = this._contexts.slice(0);
for (let i = 0, len = callbacks.length; i < len; i++) {
try {

@@ -72,51 +61,45 @@ ret.push(callbacks[i].apply(contexts[i], args));

return ret;
};
CallbackList.prototype.isEmpty = function () {
}
isEmpty() {
return !this._callbacks || this._callbacks.length === 0;
};
CallbackList.prototype.dispose = function () {
}
dispose() {
this._callbacks = undefined;
this._contexts = undefined;
};
return CallbackList;
}());
var Emitter = /** @class */ (function () {
function Emitter(_options) {
}
}
export class Emitter {
constructor(_options) {
this._options = _options;
}
Object.defineProperty(Emitter.prototype, "event", {
/**
* Allows the public to subscribe to events from this Emitter
*/
get: function () {
var _this = this;
if (!this._event) {
this._event = function (listener, thisArgs, disposables) {
if (!_this._callbacks) {
_this._callbacks = new CallbackList();
}
if (_this._options && _this._options.onFirstListenerAdd && _this._callbacks.isEmpty()) {
_this._options.onFirstListenerAdd(_this);
}
_this._callbacks.add(listener, thisArgs);
var result = {
dispose: function () {
_this._callbacks.remove(listener, thisArgs);
result.dispose = Emitter._noop;
if (_this._options && _this._options.onLastListenerRemove && _this._callbacks.isEmpty()) {
_this._options.onLastListenerRemove(_this);
}
},
};
if (Array.isArray(disposables)) {
disposables.push(result);
}
return result;
/**
* Allows the public to subscribe to events from this Emitter
*/
get event() {
if (!this._event) {
this._event = (listener, thisArgs, disposables) => {
if (!this._callbacks) {
this._callbacks = new CallbackList();
}
if (this._options && this._options.onFirstListenerAdd && this._callbacks.isEmpty()) {
this._options.onFirstListenerAdd(this);
}
this._callbacks.add(listener, thisArgs);
const result = {
dispose: () => {
this._callbacks.remove(listener, thisArgs);
result.dispose = Emitter._noop;
if (this._options && this._options.onLastListenerRemove && this._callbacks.isEmpty()) {
this._options.onLastListenerRemove(this);
}
},
};
}
return this._event;
},
enumerable: true,
configurable: true
});
if (Array.isArray(disposables)) {
disposables.push(result);
}
return result;
};
}
return this._event;
}
/**

@@ -126,8 +109,8 @@ * To be kept private to fire an event to

*/
Emitter.prototype.fire = function (event) {
fire(event) {
if (this._callbacks) {
this._callbacks.invoke.call(this._callbacks, event);
}
};
Emitter.prototype.dispose = function () {
}
dispose() {
if (this._callbacks) {

@@ -137,9 +120,7 @@ this._callbacks.dispose();

}
};
Emitter._noop = function () {
// nada
};
return Emitter;
}());
exports.Emitter = Emitter;
}
}
Emitter._noop = () => {
// nada
};
//# sourceMappingURL=emitter.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
tslib_1.__exportStar(require("./emitter"), exports);
export * from './emitter';
//# sourceMappingURL=index.js.map

@@ -1,3 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
{
"name": "@stoplight/emitter",
"version": "0.0.43",
"version": "0.0.44-alpha.0",
"description": "Stoplight Emitter type and interface definitions.",

@@ -25,3 +25,3 @@ "main": "lib/index.js",

},
"gitHead": "863127087b0dcfaebf40e7c0ed86bedcd2835468"
"gitHead": "ba495e3f8984dd68df510ccfbc2d8401515c4161"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc