Skip to content

Commit

Permalink
Merge pull request #1751 from BladeRunnerJS/update-emitr-library
Browse files Browse the repository at this point in the history
Update emitr library
  • Loading branch information
thecapdan authored Nov 25, 2016
2 parents ef56fba + 741bdc9 commit 155ddd8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
18 changes: 12 additions & 6 deletions brjs-sdk/sdk/libs/javascript/emitr/dist/emitr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ var MultiMap = require('./MultiMap');
///////////////////////////////////////////////////////////////////////////
var ONCE_FUNCTION_MARKER = {};

function notify(listeners, args) {
function notify(listeners, suppressErrors, args) {
if (listeners.length === 0) { return false; }
// take a copy in case one of the callbacks modifies the listeners array.
listeners = listeners.slice();
for (var i = 0, len = listeners.length; i < len; ++i) {
var listener = listeners[i];
try {
if (suppressErrors) {
try {
listener.callback.apply(listener.context, args);
} catch (e) {
// Swallowing the errors will make this for-loop resilient
}
} else {
listener.callback.apply(listener.context, args);
} catch(e) {
// do nothing
}
}
return true;
Expand Down Expand Up @@ -51,6 +55,8 @@ function Emitter() {
this._emitterMetaEventsOn = false;
}

Emitter.suppressErrors = true;

Emitter.prototype = {
/**
* Registers a listener for an event.
Expand Down Expand Up @@ -204,7 +210,7 @@ Emitter.prototype = {
args = slice.call(arguments, 1);
if (this._emitterListeners.hasAny(event)) {
anyListeners = true;
notify(this._emitterListeners.getValues(event), args);
notify(this._emitterListeners.getValues(event), Emitter.suppressErrors, args);
}

// navigate up the prototype chain emitting against the constructors.
Expand All @@ -213,7 +219,7 @@ Emitter.prototype = {
while (proto !== null && proto !== last) {
if (this._emitterListeners.hasAny(proto.constructor)) {
anyListeners = true;
notify(this._emitterListeners.getValues(proto.constructor), arguments);
notify(this._emitterListeners.getValues(proto.constructor), Emitter.suppressErrors, arguments);
}
last = proto;
proto = Object.getPrototypeOf(proto);
Expand Down
17 changes: 11 additions & 6 deletions brjs-sdk/sdk/libs/javascript/emitr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "emitr",
"version": "0.0.8",
"version": "0.0.9",
"description": "An node/browser event emitter that supports dispatching based on types.",
"homepage": "http://BladeRunnerJS.github.io/emitr",
"license": "MIT",
Expand All @@ -10,19 +10,22 @@
},
"main": "./src/index.js",
"scripts": {
"prepublish": "browserify src/index.js -s emitr -o dist/emitr.js",
"test": "npm run test:lint && npm run test:node && npm run test:browser && npm run test:saucelabs",
"test:lint": "eslint src test",
"prepublish": "mkdirp dist && browserify src/index.js -s emitr -o dist/emitr.js",
"postpublish": "publish-release --assets dist/emitr.js --notes 'Add release notes here.'",
"pretest": "npm run pretest:lint",
"pretest:lint": "eslint src test",
"test": "npm run test:node && npm run test:browser && npm run test:saucelabs",
"test:node": "mocha test",
"test:node:debug": "mocha test -w",
"test:browser": "karma start",
"test:browser:debug": "karma start karma-debug.conf.js",
"test:saucelabs": "karma start karma-saucelabs.conf.js"
"test:saucelabs": "envcheck SAUCE_ACCESS_KEY && karma start karma-saucelabs.conf.js"
},
"devDependencies": {
"browserify": "^11.0.0",
"chai": "^3.2.0",
"core-js": "^1.0.1",
"env-check": "^0.0.1",
"eslint": "^0.24.1",
"expectations": "^0.5.1",
"karma": "^0.13.6",
Expand All @@ -32,6 +35,8 @@
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.2.0",
"karma-sauce-launcher": "^0.2.14",
"mocha": "^2.2.5"
"mkdirp": "^0.5.1",
"mocha": "^2.2.5",
"publish-release": "^1.0.2"
}
}
18 changes: 12 additions & 6 deletions brjs-sdk/sdk/libs/javascript/emitr/src/Emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ var MultiMap = require('./MultiMap');
///////////////////////////////////////////////////////////////////////////
var ONCE_FUNCTION_MARKER = {};

function notify(listeners, args) {
function notify(listeners, suppressErrors, args) {
if (listeners.length === 0) { return false; }
// take a copy in case one of the callbacks modifies the listeners array.
listeners = listeners.slice();
for (var i = 0, len = listeners.length; i < len; ++i) {
var listener = listeners[i];
try {
if (suppressErrors) {
try {
listener.callback.apply(listener.context, args);
} catch (e) {
// Swallowing the errors will make this for-loop resilient
}
} else {
listener.callback.apply(listener.context, args);
} catch(e) {
// do nothing
}
}
return true;
Expand Down Expand Up @@ -50,6 +54,8 @@ function Emitter() {
this._emitterMetaEventsOn = false;
}

Emitter.suppressErrors = true;

Emitter.prototype = {
/**
* Registers a listener for an event.
Expand Down Expand Up @@ -203,7 +209,7 @@ Emitter.prototype = {
args = slice.call(arguments, 1);
if (this._emitterListeners.hasAny(event)) {
anyListeners = true;
notify(this._emitterListeners.getValues(event), args);
notify(this._emitterListeners.getValues(event), Emitter.suppressErrors, args);
}

// navigate up the prototype chain emitting against the constructors.
Expand All @@ -212,7 +218,7 @@ Emitter.prototype = {
while (proto !== null && proto !== last) {
if (this._emitterListeners.hasAny(proto.constructor)) {
anyListeners = true;
notify(this._emitterListeners.getValues(proto.constructor), arguments);
notify(this._emitterListeners.getValues(proto.constructor), Emitter.suppressErrors, arguments);
}
last = proto;
proto = Object.getPrototypeOf(proto);
Expand Down

0 comments on commit 155ddd8

Please sign in to comment.