From c74b7038eadfe4abb89ca841637bbe4048fad5b3 Mon Sep 17 00:00:00 2001 From: Michael Cavalea Date: Thu, 17 Dec 2015 14:45:29 -0500 Subject: [PATCH] fail silently if emitting a nonexistant event --- dist/knot.min.js | 4 ++-- package.json | 2 +- src/knot.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/knot.min.js b/dist/knot.min.js index 4f54e7c..8e9cc1a 100644 --- a/dist/knot.min.js +++ b/dist/knot.min.js @@ -1,6 +1,6 @@ /*! - * Knot.js 0.2.0 - A browser-based emitter, for tying together event handlers. + * Knot.js 0.2.1 - A browser-based emitter, for tying together event handlers. * Copyright (c) 2015 Michael Cavalea - https://github.com/callmecavs/knot * License: MIT */ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.Knot=e()}}(function(){return function e(n,t,r){function o(u,i){if(!t[u]){if(!n[u]){var s="function"==typeof require&&require;if(!i&&s)return s(u,!0);if(f)return f(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return o(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var f="function"==typeof require&&require,u=0;u1?t-1:0),o=1;t>o;o++)r[o-1]=arguments[o];var f=e.events[n].slice();return f.forEach(function(t){t._once&&e.off(n,t),t.apply(e,r)}),e},e},n.exports=t["default"]},{}]},{},[1])(1)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.Knot=e()}}(function(){return function e(n,t,r){function o(u,i){if(!t[u]){if(!n[u]){var s="function"==typeof require&&require;if(!i&&s)return s(u,!0);if(f)return f(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var c=t[u]={exports:{}};n[u][0].call(c.exports,function(e){var t=n[u][1][e];return o(t?t:e)},c,c.exports,e,n,t,r)}return t[u].exports}for(var f="function"==typeof require&&require,u=0;u1?t-1:0),o=1;t>o;o++)r[o-1]=arguments[o];var f=e.events[n]&&e.events[n].slice();return f&&f.forEach(function(t){t._once&&e.off(n,t),t.apply(e,r)}),e},e},n.exports=t["default"]},{}]},{},[1])(1)}); \ No newline at end of file diff --git a/package.json b/package.json index a5f8f42..e1138cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "knot.js", - "version": "0.2.0", + "version": "0.2.1", "description": "A browser-based emitter, for tying together event handlers.", "homepage": "https://github.com/callmecavs/knot", "main": "dist/knot.min.js", diff --git a/src/knot.js b/src/knot.js index 6a6d59e..b5a412e 100644 --- a/src/knot.js +++ b/src/knot.js @@ -23,10 +23,10 @@ export default (object = {}) => { object.emit = function(name, ...args) { // cache event state, to avoid consequences of mutation from splice while firing handlers - const cached = object.events[name].slice() + const cached = object.events[name] && object.events[name].slice() - // fire handlers - cached.forEach(handler => { + // if they exist, fire handlers + cached && cached.forEach(handler => { // remove handler if added with `once` handler._once && object.off(name, handler)