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

typed-emitter

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-emitter - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

9

.eslintrc.js

@@ -5,3 +5,9 @@ module.exports = {

indent: ['error', 4],
quotes: ['error', 'single']
quotes: ['error', 'single'],
// demoted to es5, so don't use the new sugar
'no-var': 0,
'object-shorthand': 0,
'vars-on-top': 0,
'prefer-arrow-callback': 0,
},

@@ -12,4 +18,5 @@ globals: {

parserOptions: {
ecmaVersion: 5,
sourceType: 'script',
},
};

78

emitter.js
/* eslint no-underscore-dangle: 0 */
'use strict';
const each = require('lodash/forEach');
class Emitter {
constructor() {
this._listeners = {};
this._onQueue = [];
this._offQueue = [];
this._triggerStack = [];
}
var each = require('lodash/forEach');
var defaults = require('lodash/defaults');
on(ctx, ev, fn) {
function Emitter() {
this._listeners = {};
this._onQueue = [];
this._offQueue = [];
this._triggerStack = [];
}
Emitter.prototype = {
on: function on(ctx, ev, fn) {
if (!this._listeners[ev]) {

@@ -18,3 +20,3 @@ this._listeners[ev] = [];

const listener = { ctx, ev, fn };
var listener = { ctx: ctx, ev: ev, fn: fn };
if (!this._triggering) {

@@ -25,9 +27,11 @@ this._listeners[ev].push(listener);

}
}
off(ctx) {
return this;
},
off: function off(ctx) {
if (!this._triggering) {
each(this._listeners, listeners => {
for (let i = 0, len = listeners.length; i < len; i++) {
const listener = listeners[i];
each(this._listeners, function offListeners(listeners) {
for (var i = 0, len = listeners.length; i < len; i++) {
var listener = listeners[i];
if (listener.ctx === ctx) {

@@ -43,8 +47,10 @@ listeners.splice(i, 1);

}
}
trigger(ev) {
return this;
},
trigger: function trigger(ev) {
if (this._triggering) {
this._triggerStack.unshift(ev);
return;
return this;
}

@@ -54,7 +60,7 @@

const type = ev.type;
const listeners = this._listeners[type];
var type = ev.type;
var listeners = this._listeners[type];
if (listeners) {
for (let i = 0, len = listeners.length; i < len; i++) {
const listener = listeners[i];
for (var i = 0, len = listeners.length; i < len; i++) {
var listener = listeners[i];
listener.fn.call(listener.ctx, ev);

@@ -66,5 +72,19 @@ }

this._processQueue();
}
_processQueue() {
return this;
},
factory: function factory(evProps) {
var that = this;
var triggerer = function triggerer(ev) {
return that.trigger(defaults({}, evProps, ev));
};
triggerer.trigger = triggerer;
triggerer.factory = function triggererFactory(subEvProps) {
return that.factory(defaults({}, evProps, subEvProps));
};
return triggerer;
},
_processQueue: function _processQueue() {
if (this._triggering) {

@@ -74,3 +94,3 @@ return;

each(this._offQueue, ctx => {
each(this._offQueue, function offQueue(ctx) {
this.off(ctx);

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

each(this._onQueue, listener => {
each(this._onQueue, function onQueue(listener) {
this.on(listener.ctx, listener.ev, listener.fn);

@@ -87,8 +107,8 @@ });

if (this._triggerStack.length) {
const ev = this._triggerStack.pop();
var ev = this._triggerStack.pop();
this.trigger(ev);
}
}
}
},
};
module.exports = Emitter;
{
"name": "typed-emitter",
"version": "0.0.1",
"version": "0.0.2",
"description": "Basic pub/sub/emitter class for React apps, inspired by Flux",

@@ -5,0 +5,0 @@ "main": "emitter.js",

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