Socket
Socket
Sign inDemoInstall

mini-signals

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mini-signals - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

src/index.js

245

browser.js

@@ -1,159 +0,144 @@

(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define('MiniSignal', ['exports', 'module'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module);
} else {
var mod = {
exports: {}
};
factory(mod.exports, mod);
global.MiniSignal = mod.exports;
}
})(this, function (exports, module) {
'use strict';
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.MiniSignal = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
Object.defineProperty(exports, '__esModule', {
value: true
});
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var MiniSignalBinding = function MiniSignalBinding(fn) {
var once = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
_classCallCheck(this, MiniSignalBinding);
var MiniSignalBinding = function MiniSignalBinding(fn) {
var once = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1];
this._fn = fn;
this._next = this._prev = null;
this._once = once;
};
_classCallCheck(this, MiniSignalBinding);
var MiniSignal = (function () {
function MiniSignal() {
_classCallCheck(this, MiniSignal);
this._fn = fn;
this._next = this._prev = null;
this._once = once;
};
this._head = this._tail = undefined;
}
function _addMiniSignalBinding(self, node) {
if (!self._head) {
self._head = node;
self._tail = node;
} else {
self._tail._next = node;
node._prev = self._tail;
self._tail = node;
}
_createClass(MiniSignal, [{
key: 'handlers',
value: function handlers() {
var exists = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
node.detach = (function () {
self.detach(this);
}).bind(node);
var node = this._head;
return node;
}
if (exists) {
return !!node;
}
var MiniSignal = (function () {
function MiniSignal() {
_classCallCheck(this, MiniSignal);
var ee = [];
this._head = this._tail = undefined;
}
while (node) {
ee.push(node);
node = node._next;
}
_createClass(MiniSignal, [{
key: 'handlers',
value: function handlers() {
var exists = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0];
return ee;
var node = this._head;
if (exists) {
return !!node;
}
}, {
key: 'dispatch',
value: function dispatch() {
var node = this._head;
if (!node) {
return false;
}
var ee = [];
while (node) {
node._fn.apply(this, arguments);
if (node._once) {
this.detach(node);
}
node = node._next;
}
while (node) {
ee.push(node);
node = node._next;
}
return true;
return ee;
}
}, {
key: 'dispatch',
value: function dispatch() {
var node = this._head;
if (!node) {
return false;
}
}, {
key: 'add',
value: function add(fn) {
if (typeof fn !== 'function') {
throw new Error('MiniSignal#add(): First arg must be a Function.');
while (node) {
node._fn.apply(this, arguments);
if (node._once) {
this.detach(node);
}
var node = new MiniSignalBinding(fn);
return this._addMiniSignalBinding(node);
node = node._next;
}
}, {
key: 'once',
value: function once(fn) {
if (typeof fn !== 'function') {
throw new Error('MiniSignal#once(): First arg must be a Function.');
}
var node = new MiniSignalBinding(fn, true);
return this._addMiniSignalBinding(node);
}
}, {
key: '_addMiniSignalBinding',
value: function _addMiniSignalBinding(node) {
if (!this._head) {
this._head = node;
this._tail = node;
} else {
this._tail._next = node;
node._prev = this._tail;
this._tail = node;
}
var self = this;
node.detach = (function () {
self.detach(this);
}).bind(node);
return node;
return true;
}
}, {
key: 'add',
value: function add(fn) {
if (typeof fn !== 'function') {
throw new Error('MiniSignal#add(): First arg must be a Function.');
}
}, {
key: 'detach',
value: function detach(node) {
if (!(node instanceof MiniSignalBinding)) {
throw new Error('MiniSignal#detach(): First arg must be a MiniSignalBinding object.');
}
if (!node._fn) {
return this;
}
if (node === this._head) {
this._head = node._next;
if (!this._head) {
this._tail = null;
} else {
this._head._prev = null;
}
} else if (node === this._tail) {
this._tail = node._prev;
this._tail._next = null;
} else {
node._prev._next = node._next;
node._next._prev = node._prev;
}
node._fn = null;
node._context = null;
return _addMiniSignalBinding(this, new MiniSignalBinding(fn));
}
}, {
key: 'once',
value: function once(fn) {
if (typeof fn !== 'function') {
throw new Error('MiniSignal#once(): First arg must be a Function.');
}
return _addMiniSignalBinding(this, new MiniSignalBinding(fn, true));
}
}, {
key: 'detach',
value: function detach(node) {
if (!(node instanceof MiniSignalBinding)) {
throw new Error('MiniSignal#detach(): First arg must be a MiniSignalBinding object.');
}
if (!node._fn) {
return this;
}
}, {
key: 'detachAll',
value: function detachAll() {
var node = this._head;
if (!node) {
return this;
if (node === this._head) {
this._head = node._next;
if (!this._head) {
this._tail = null;
} else {
this._head._prev = null;
}
this._head = this._tail = null;
return this;
} else if (node === this._tail) {
this._tail = node._prev;
this._tail._next = null;
} else {
node._prev._next = node._next;
node._next._prev = node._prev;
}
}]);
node._fn = null;
return this;
}
}, {
key: 'detachAll',
value: function detachAll() {
this._head = this._tail = null;
return this;
}
}]);
return MiniSignal;
})();
return MiniSignal;
})();
MiniSignal.MiniSignalBinding = MiniSignalBinding;
MiniSignal.MiniSignalBinding = MiniSignalBinding;
module.exports = MiniSignal;
});
exports['default'] = MiniSignal;
module.exports = exports['default'];
},{}]},{},[1])(1)
});

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

(function(global,factory){if(typeof define==="function"&&define.amd){define("MiniSignal",["exports","module"],factory)}else if(typeof exports!=="undefined"&&typeof module!=="undefined"){factory(exports,module)}else{var mod={exports:{}};factory(mod.exports,mod);global.MiniSignal=mod.exports}})(this,function(exports,module){"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var MiniSignalBinding=function MiniSignalBinding(fn){var once=arguments.length<=1||arguments[1]===undefined?false:arguments[1];_classCallCheck(this,MiniSignalBinding);this._fn=fn;this._next=this._prev=null;this._once=once};var MiniSignal=function(){function MiniSignal(){_classCallCheck(this,MiniSignal);this._head=this._tail=undefined}_createClass(MiniSignal,[{key:"handlers",value:function handlers(){var exists=arguments.length<=0||arguments[0]===undefined?false:arguments[0];var node=this._head;if(exists){return!!node}var ee=[];while(node){ee.push(node);node=node._next}return ee}},{key:"dispatch",value:function dispatch(){var node=this._head;if(!node){return false}while(node){node._fn.apply(this,arguments);if(node._once){this.detach(node)}node=node._next}return true}},{key:"add",value:function add(fn){if(typeof fn!=="function"){throw new Error("MiniSignal#add(): First arg must be a Function.")}var node=new MiniSignalBinding(fn);return this._addMiniSignalBinding(node)}},{key:"once",value:function once(fn){if(typeof fn!=="function"){throw new Error("MiniSignal#once(): First arg must be a Function.")}var node=new MiniSignalBinding(fn,true);return this._addMiniSignalBinding(node)}},{key:"_addMiniSignalBinding",value:function _addMiniSignalBinding(node){if(!this._head){this._head=node;this._tail=node}else{this._tail._next=node;node._prev=this._tail;this._tail=node}var self=this;node.detach=function(){self.detach(this)}.bind(node);return node}},{key:"detach",value:function detach(node){if(!(node instanceof MiniSignalBinding)){throw new Error("MiniSignal#detach(): First arg must be a MiniSignalBinding object.")}if(!node._fn){return this}if(node===this._head){this._head=node._next;if(!this._head){this._tail=null}else{this._head._prev=null}}else if(node===this._tail){this._tail=node._prev;this._tail._next=null}else{node._prev._next=node._next;node._next._prev=node._prev}node._fn=null;node._context=null;return this}},{key:"detachAll",value:function detachAll(){var node=this._head;if(!node){return this}this._head=this._tail=null;return this}}]);return MiniSignal}();MiniSignal.MiniSignalBinding=MiniSignalBinding;module.exports=MiniSignal});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.MiniSignal=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var MiniSignalBinding=function MiniSignalBinding(fn){var once=arguments.length<=1||arguments[1]===undefined?false:arguments[1];_classCallCheck(this,MiniSignalBinding);this._fn=fn;this._next=this._prev=null;this._once=once};function _addMiniSignalBinding(self,node){if(!self._head){self._head=node;self._tail=node}else{self._tail._next=node;node._prev=self._tail;self._tail=node}node.detach=function(){self.detach(this)}.bind(node);return node}var MiniSignal=function(){function MiniSignal(){_classCallCheck(this,MiniSignal);this._head=this._tail=undefined}_createClass(MiniSignal,[{key:"handlers",value:function handlers(){var exists=arguments.length<=0||arguments[0]===undefined?false:arguments[0];var node=this._head;if(exists){return!!node}var ee=[];while(node){ee.push(node);node=node._next}return ee}},{key:"dispatch",value:function dispatch(){var node=this._head;if(!node){return false}while(node){node._fn.apply(this,arguments);if(node._once){this.detach(node)}node=node._next}return true}},{key:"add",value:function add(fn){if(typeof fn!=="function"){throw new Error("MiniSignal#add(): First arg must be a Function.")}return _addMiniSignalBinding(this,new MiniSignalBinding(fn))}},{key:"once",value:function once(fn){if(typeof fn!=="function"){throw new Error("MiniSignal#once(): First arg must be a Function.")}return _addMiniSignalBinding(this,new MiniSignalBinding(fn,true))}},{key:"detach",value:function detach(node){if(!(node instanceof MiniSignalBinding)){throw new Error("MiniSignal#detach(): First arg must be a MiniSignalBinding object.")}if(!node._fn){return this}if(node===this._head){this._head=node._next;if(!this._head){this._tail=null}else{this._head._prev=null}}else if(node===this._tail){this._tail=node._prev;this._tail._next=null}else{node._prev._next=node._next;node._next._prev=node._prev}node._fn=null;return this}},{key:"detachAll",value:function detachAll(){this._head=this._tail=null;return this}}]);return MiniSignal}();MiniSignal.MiniSignalBinding=MiniSignalBinding;exports["default"]=MiniSignal;module.exports=exports["default"]},{}]},{},[1])(1)});
// main entry point for commonjs, exports MiniSignal
var minisignal = require('./lib/mini-signals');
exports = minisignal['default'];
exports.MiniSignal = minisignal.MiniSignal;
exports.MiniSignalBinding = minisignal.MiniSignalBinding;
module.exports = exports;
module.exports = require('./lib/mini-signals');

@@ -21,4 +21,19 @@ 'use strict';

exports.MiniSignalBinding = MiniSignalBinding;
function _addMiniSignalBinding(self, node) {
if (!self._head) {
self._head = node;
self._tail = node;
} else {
self._tail._next = node;
node._prev = self._tail;
self._tail = node;
}
node.detach = (function () {
self.detach(this);
}).bind(node);
return node;
}
var MiniSignal = (function () {

@@ -76,4 +91,3 @@ function MiniSignal() {

}
var node = new MiniSignalBinding(fn);
return this._addMiniSignalBinding(node);
return _addMiniSignalBinding(this, new MiniSignalBinding(fn));
}

@@ -86,25 +100,5 @@ }, {

}
var node = new MiniSignalBinding(fn, true);
return this._addMiniSignalBinding(node);
return _addMiniSignalBinding(this, new MiniSignalBinding(fn, true));
}
}, {
key: '_addMiniSignalBinding',
value: function _addMiniSignalBinding(node) {
if (!this._head) {
this._head = node;
this._tail = node;
} else {
this._tail._next = node;
node._prev = this._tail;
this._tail = node;
}
var self = this;
node.detach = (function () {
self.detach(this);
}).bind(node);
return node;
}
}, {
key: 'detach',

@@ -133,3 +127,2 @@ value: function detach(node) {

node._fn = null;
node._context = null;
return this;

@@ -140,7 +133,2 @@ }

value: function detachAll() {
var node = this._head;
if (!node) {
return this;
}
this._head = this._tail = null;

@@ -154,4 +142,5 @@ return this;

exports.MiniSignal = MiniSignal;
MiniSignal.MiniSignalBinding = MiniSignalBinding;
exports['default'] = MiniSignal;
//# sourceMappingURL=mini-signals.js.map
module.exports = exports['default'];
{
"name": "mini-signals",
"version": "1.0.1",
"version": "1.0.2",
"description": "signals, in JavaScript, fast",
"main": "index.js",
"main": "lib/mini-signals.js",
"jsnext:main": "src/mini-signals.js",
"browser": "browser.js",
"jspm": {
"main": "index.js"
},
"scripts": {
"test": "npm run mocha",
"test:fast": "mocha --compilers js:babel/register ./test/mini-signals-spec.js",
"test:deopt": "node --trace_opt --trace_deopt ./bench/test-deopt.js | grep \"disabled optimization\"",
"lint": "eslint src/mini-signals.js",
"build": "npm run babel && npm run roll && npm run uglify",
"babel": "babel src/ -m umd -d lib -m common -s --no-comments",
"roll": "rollup index.es6.js | babel -m umd -o browser.js --module-id MiniSignal --no-comments",
"build": "npm run rollup && npm run browserify && npm run uglify && npm run jsdoc2md",
"rollup": "rollup ./src/index.js | babel -o ./lib/mini-signals.js --no-comments",
"browserify": "browserify ./lib/mini-signals.js -o browser.js -s MiniSignal",
"uglify": "uglifyjs browser.js -o browser.min.js",
"coverage": "istanbul cover -- ./node_modules/mocha/bin/_mocha --compilers js:babel/register ./test/mini-signals-*.js",
"mocha": "mocha --compilers js:babel/register",
"bench": "npm run build && node ./bench/emit.js",
"prepublish": "npm run build && npm test",
"jsdoc2md": "jsdoc-parse ./src/mini-signals.js | dmd > api.md"
"bench": "babel-node ./bench/emit.js",
"_prepublish": "npm run build && npm test",
"jsdoc2md": "jsdoc-parse ./src/mini-signals.js | dmd > API.md"
},
"repository": {
"type": "git",
"url": "git://github.com/Hypercubed/mini-signals.git"
"url": "https://github.com/Hypercubed/mini-signals.git"
},

@@ -44,2 +41,3 @@ "keywords": [

"benchmark": "^1.0.0",
"browserify": "^11.2.0",
"dmd": "^1.2.0",

@@ -46,0 +44,0 @@ "eslint": "^1.5.0",

@@ -19,2 +19,22 @@ /*jshint -W097 */

/**
* @private
*/
function _addMiniSignalBinding(self, node) {
if (!self._head) {
self._head = node;
self._tail = node;
} else {
self._tail._next = node;
node._prev = self._tail;
self._tail = node;
}
node.detach = (function() {
self.detach(this);
}).bind(node);
return node;
}
export class MiniSignal {

@@ -26,2 +46,8 @@

* @api public
*
* @example
* let mySignal = new MiniSignal();
* let binding = mySignal.add(onSignal);
* mySignal.dispatch('foo', 'bar');
* mySignal.detach(binding);
*/

@@ -40,7 +66,7 @@ constructor() {

handlers(exists = false) {
var node = this._head;
let node = this._head;
if (exists) { return !!node; }
var ee = [];
const ee = [];

@@ -62,3 +88,3 @@ while (node) {

dispatch() {
var node = this._head;
let node = this._head;

@@ -87,4 +113,3 @@ if (!node) { return false; }

}
var node = new MiniSignalBinding(fn);
return this._addMiniSignalBinding(node);
return _addMiniSignalBinding(this, new MiniSignalBinding(fn));
}

@@ -103,24 +128,5 @@

}
var node = new MiniSignalBinding(fn, true);
return this._addMiniSignalBinding(node);
return _addMiniSignalBinding(this, new MiniSignalBinding(fn, true));
}
_addMiniSignalBinding(node) {
if (!this._head) {
this._head = node;
this._tail = node;
} else {
this._tail._next = node;
node._prev = this._tail;
this._tail = node;
}
var self = this;
node.detach = (function() {
self.detach(this);
}).bind(node);
return node;
}
/**

@@ -152,3 +158,2 @@ * Remove binding object.

node._fn = null;
node._context = null;
return this;

@@ -164,5 +169,2 @@ }

detachAll() {
var node = this._head;
if (!node) { return this; }
this._head = this._tail = null;

@@ -169,0 +171,0 @@ return this;

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