Skip to content

Commit

Permalink
Merge pull request #9 from Psychopoulet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Psychopoulet committed Jul 29, 2018
2 parents 467dcb2 + 3178e11 commit aedf3bc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ node_js:
install:
- "npm install -g typescript"
- "npm install"
script: "npm run-script tests"
script: "npm run-script ci"
4 changes: 0 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

// consts

const ISTRAVIS = (0, process).env.TRAVIS || false;

const APP_FILES = [ path.join(__dirname, "lib", "**", "*.js") ];
const UNITTESTS_FILES = [ path.join(__dirname, "tests", "**", "*.js") ];

Expand Down Expand Up @@ -75,8 +73,6 @@

}));

gulp.task("tests", gulp.series(ISTRAVIS ? "coveralls" : "mocha"));

// watcher

gulp.task("watch", () => {
Expand Down
41 changes: 25 additions & 16 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ module.exports = class AsynchronousEventEmitter extends require("events") {
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}

else if (!this._events || !this._events.error) {
throw new Error("You MUST implement \"error\" handler before emit anything");
}
else if (!this._events[eventName]) {
return this;
}

else {

Promise.resolve().then(() => {
Expand Down Expand Up @@ -75,15 +77,17 @@ module.exports = class AsynchronousEventEmitter extends require("events") {
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}

else if ("undefined" === typeof listener) {
throw new ReferenceError("Missing \"listener\" parameter");
}
else if ("function" !== typeof listener) {
throw new TypeError("\"listener\" must be a function");
}

else {

return super.on(eventName, listener);
Expand All @@ -100,15 +104,17 @@ module.exports = class AsynchronousEventEmitter extends require("events") {
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}

else if ("undefined" === typeof listener) {
throw new ReferenceError("Missing \"listener\" parameter");
}
else if ("function" !== typeof listener) {
throw new TypeError("\"listener\" must be a function");
}

else {

return super.once(eventName, listener);
Expand All @@ -125,15 +131,17 @@ module.exports = class AsynchronousEventEmitter extends require("events") {
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}

else if ("undefined" === typeof listener) {
throw new ReferenceError("Missing \"listener\" parameter");
}
else if ("function" !== typeof listener) {
throw new TypeError("\"listener\" must be a function");
}

else {

return super.prependListener(eventName, listener);
Expand All @@ -150,15 +158,17 @@ module.exports = class AsynchronousEventEmitter extends require("events") {
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}

else if ("undefined" === typeof listener) {
throw new ReferenceError("Missing \"listener\" parameter");
}
else if ("function" !== typeof listener) {
throw new TypeError("\"listener\" must be a function");
}

else {

return super.prependOnceListener(eventName, listener);
Expand All @@ -175,18 +185,21 @@ module.exports = class AsynchronousEventEmitter extends require("events") {
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}

else if ("undefined" === typeof listener) {
throw new ReferenceError("Missing \"listener\" parameter");
}
else if ("function" !== typeof listener) {
throw new TypeError("\"listener\" must be a function");
}

else if (!this._events || !this._events[eventName]) {
return this;
}

else {

return super.removeListener(eventName, listener);
Expand All @@ -197,19 +210,15 @@ module.exports = class AsynchronousEventEmitter extends require("events") {

removeAllListeners (eventName) {

if ("undefined" === typeof eventName) {
throw new ReferenceError("Missing \"eventName\" parameter");
if ("undefined" !== typeof eventName && ("string" !== typeof eventName && "symbol" !== typeof eventName)) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("string" === typeof eventName && "" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}
else if ("string" !== typeof eventName && "symbol" !== typeof eventName) {
throw new TypeError("\"eventName\" must be a String or a Symbol");
}
else if ("" === eventName.trim()) {
throw new Error("\"eventName\" cannot be empty");
}
else {

else {
return super.removeAllListeners(eventName);

}

}
Expand Down
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "asynchronous-eventemitter",
"version": "0.3.3",
"version": "0.3.4",
"description": "Asynchronous version of EventEmitter, secured by promises",
"main": "lib/main.js",
"typings": "lib/index.d.ts",
"scripts": {
"tests": "gulp tests"
"ci": "gulp coveralls",
"precommit": "gulp eslint",
"prepush": "gulp mocha"
},
"pre-push": [
"tests"
],
"repository": {
"type": "git",
"url": "git://github.com/Psychopoulet/asynchronous-eventemitter.git"
Expand All @@ -28,14 +27,14 @@
},
"dependencies": {},
"devDependencies": {
"@types/node": "9.6.7",
"@types/node": "10.5.4",
"gulp": "4.0.0",
"gulp-coveralls": "0.1.4",
"gulp-eslint": "4.0.2",
"gulp-eslint": "5.0.0",
"gulp-istanbul": "1.1.3",
"gulp-mocha": "3.0.1",
"gulp-plumber": "1.2.0",
"pre-push": "0.1.1"
"husky": "0.14.3"
},
"homepage": "https://github.com/Psychopoulet/asynchronous-eventemitter#readme",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion tests/removeAllListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("removeAllListeners", () => {

it("should check missing args", () => {

assert.throws(() => {
assert.doesNotThrow(() => {
new Events().removeAllListeners();
}, ReferenceError, "check missing eventName does not throw an error");

Expand Down

0 comments on commit aedf3bc

Please sign in to comment.