compago-listener
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -144,12 +144,8 @@ (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){ | ||
data.emitter = emitter; | ||
if (event && event.length) { | ||
for (var i = 0, l = event.length; i < l; i++) { | ||
event[i][1].call(event[i][0], data); | ||
var handlers = event ? all ? [].concat(event, all) : event.slice() : all ? all.slice() : []; | ||
if (handlers.length) { | ||
for (var i = 0, l = handlers.length; i < l; i++) { | ||
handlers[i][1].call(handlers[i][0], data); | ||
} | ||
} | ||
if (all && all.length) { | ||
for (var i = 0, l = all.length; i < l; i++) { | ||
all[i][1].call(all[i][0], data); | ||
} | ||
} | ||
return this; | ||
@@ -156,0 +152,0 @@ }, |
@@ -1,1 +0,1 @@ | ||
!function e(t,r,n){function i(o,a){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var v=r[o]={exports:{}};t[o][0].call(v.exports,function(e){var r=t[o][1][e];return i(r?r:e)},v,v.exports,e,t,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,r){"use strict";var n=function(){function e(e,t){var r=[],n=!0,i=!1,s=void 0;try{for(var o,a=e[Symbol.iterator]();!(n=(o=a.next()).done)&&(r.push(o.value),!t||r.length!==t);n=!0);}catch(u){i=!0,s=u}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw s}}return r}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();Object.defineProperty(r,"__esModule",{value:!0});var i=/\s+/;r.Listener={_events:void 0,_listeners:void 0,on:function(e,t,r){for(var n=i.test(t)?t.split(i):[t],s=e._events||(e._events=new Map),o=this._listeners||(this._listeners=new Map),a=o.get(e)||o.set(e,[]).get(e),u=0,f=n.length;f>u;u++){var v=n[u],l=s.get(v)||s.set(v,[]).get(v);l.push([this,r]),~a.indexOf(v)||a.push(v)}return this},off:function(e,t,r){var n=this,s=this._listeners;if(!s||!s.size)return this;t=t?i.test(t)?t.split(i):[t]:void 0;var o=!t&&!r,a=s;if(e){if(!e._events||!e._events.size)return this;a=new Map,a.set(e,s.get(e))}return a.forEach(function(e,i){for(var a=t||e,u=a.length-1;u>=0;u--){var f=void 0,v=a[u],l=i._events&&i._events.get(v);if(l){for(var h=l.length-1;h>=0;h--)if(l[h][0]===n){if(r&&r!==l[h][1]){f=!0;continue}l.splice(h,1)}o||f||e.splice(e.indexOf(v),1),l.length||i._events["delete"](v)}}(o||!e[0])&&s["delete"](i)}),this},emit:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=arguments.length<=2||void 0===arguments[2]?this:arguments[2];if(!e)return this;if(!this._events||!this._events.size)return this;var n=this._events.get(e),i=this._events.get("all");if(t.event=e,t.emitter=r,n&&n.length)for(var s=0,o=n.length;o>s;s++)n[s][1].call(n[s][0],t);if(i&&i.length)for(var s=0,o=i.length;o>s;s++)i[s][1].call(i[s][0],t);return this},free:function(){var e=this,t=this._events;return t?(t.forEach(function(t){var r=!0,i=!1,s=void 0;try{for(var o,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var u=n(o.value,2),f=u[0];u[1];f._listeners["delete"](e)}}catch(v){i=!0,s=v}finally{try{!r&&a["return"]&&a["return"]()}finally{if(i)throw s}}}),this._events=void 0,this):this}}},{}]},{},[1]); | ||
!function e(t,r,n){function i(o,a){if(!r[o]){if(!t[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var v=r[o]={exports:{}};t[o][0].call(v.exports,function(e){var r=t[o][1][e];return i(r?r:e)},v,v.exports,e,t,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,r){"use strict";var n=function(){function e(e,t){var r=[],n=!0,i=!1,s=void 0;try{for(var o,a=e[Symbol.iterator]();!(n=(o=a.next()).done)&&(r.push(o.value),!t||r.length!==t);n=!0);}catch(u){i=!0,s=u}finally{try{!n&&a["return"]&&a["return"]()}finally{if(i)throw s}}return r}return function(t,r){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();Object.defineProperty(r,"__esModule",{value:!0});var i=/\s+/;r.Listener={_events:void 0,_listeners:void 0,on:function(e,t,r){for(var n=i.test(t)?t.split(i):[t],s=e._events||(e._events=new Map),o=this._listeners||(this._listeners=new Map),a=o.get(e)||o.set(e,[]).get(e),u=0,f=n.length;f>u;u++){var v=n[u],l=s.get(v)||s.set(v,[]).get(v);l.push([this,r]),~a.indexOf(v)||a.push(v)}return this},off:function(e,t,r){var n=this,s=this._listeners;if(!s||!s.size)return this;t=t?i.test(t)?t.split(i):[t]:void 0;var o=!t&&!r,a=s;if(e){if(!e._events||!e._events.size)return this;a=new Map,a.set(e,s.get(e))}return a.forEach(function(e,i){for(var a=t||e,u=a.length-1;u>=0;u--){var f=void 0,v=a[u],l=i._events&&i._events.get(v);if(l){for(var h=l.length-1;h>=0;h--)if(l[h][0]===n){if(r&&r!==l[h][1]){f=!0;continue}l.splice(h,1)}o||f||e.splice(e.indexOf(v),1),l.length||i._events["delete"](v)}}(o||!e[0])&&s["delete"](i)}),this},emit:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=arguments.length<=2||void 0===arguments[2]?this:arguments[2];if(!e)return this;if(!this._events||!this._events.size)return this;var n=this._events.get(e),i=this._events.get("all");t.event=e,t.emitter=r;var s=n?i?[].concat(n,i):n.slice():i?i.slice():[];if(s.length)for(var o=0,a=s.length;a>o;o++)s[o][1].call(s[o][0],t);return this},free:function(){var e=this,t=this._events;return t?(t.forEach(function(t){var r=!0,i=!1,s=void 0;try{for(var o,a=t[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var u=n(o.value,2),f=u[0];u[1];f._listeners["delete"](e)}}catch(v){i=!0,s=v}finally{try{!r&&a["return"]&&a["return"]()}finally{if(i)throw s}}}),this._events=void 0,this):this}}},{}]},{},[1]); |
@@ -143,12 +143,8 @@ 'use strict'; | ||
data.emitter = emitter; | ||
if (event && event.length) { | ||
for (let i = 0, l = event.length; i < l; i++) { | ||
event[i][1].call(event[i][0], data); | ||
const handlers = event ? all ? [].concat(event, all) : event.slice() : all ? all.slice() : []; | ||
if (handlers.length) { | ||
for (var i = 0, l = handlers.length; i < l; i++) { | ||
handlers[i][1].call(handlers[i][0], data); | ||
} | ||
} | ||
if (all && all.length) { | ||
for (let i = 0, l = all.length; i < l; i++) { | ||
all[i][1].call(all[i][0], data); | ||
} | ||
} | ||
return this; | ||
@@ -155,0 +151,0 @@ }, |
{ | ||
"name": "compago-listener", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/node/index.js", |
@@ -133,12 +133,8 @@ /** Used to split event names */ | ||
data.emitter = emitter; | ||
if (event && event.length){ | ||
for (let i = 0, l = event.length; i < l; i++) { | ||
event[i][1].call(event[i][0], data); | ||
const handlers = event ? all ? [].concat(event, all) : event.slice() : all ? all.slice() : []; | ||
if (handlers.length) { | ||
for (var i = 0, l = handlers.length; i < l; i++) { | ||
handlers[i][1].call(handlers[i][0], data); | ||
} | ||
} | ||
if (all && all.length){ | ||
for (let i = 0, l = all.length; i < l; i++) { | ||
all[i][1].call(all[i][0], data); | ||
} | ||
} | ||
return this; | ||
@@ -145,0 +141,0 @@ }, |
@@ -94,9 +94,17 @@ const Listener = require('../src/index').Listener; | ||
it('returns if there is no listener for the event', function(){ | ||
it('returns if there is no listener for any event', function(){ | ||
expect(b.emit('event')).toBe(b); | ||
}); | ||
it('returns if there is no listener for the event', function(){ | ||
a.on(b, 'someEvent', a.firstMethod); | ||
expect(b.emit('otherEvent')).toBe(b); | ||
expect(a.firstMethod).toNotHaveBeenCalled(); | ||
}); | ||
it('emits `all` event every time an event is fired', function(){ | ||
a.on(b, 'someEvent', a.secondMethod); | ||
a.on(b, 'all', a.firstMethod); | ||
b.emit('someEvent', {width:1}); | ||
expect(a.secondMethod.calls[0].arguments[0]).toEqual({event:'someEvent', emitter:b, width:1}); | ||
expect(a.firstMethod.calls[0].arguments[0]).toEqual({event:'someEvent', emitter:b, width:1}); | ||
@@ -107,2 +115,4 @@ b.emit('otherEvent'); | ||
expect(a.firstMethod.calls[2].arguments[0]).toEqual({event:'someEvent', emitter:b}); | ||
expect(a.secondMethod.calls.length).toBe(2); | ||
expect(a.firstMethod.calls.length).toBe(3); | ||
}); | ||
@@ -109,0 +119,0 @@ |
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
31679
0
100
10
644