Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
Added check for nonexistent event
  • Loading branch information
davegillem committed Dec 9, 2015
1 parent 3d80e67 commit 3be4be8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "watcher-pubsub",
"version": "1.2.1",
"version": "1.2.2",
"title": "watcher-pubsub",
"description": "A small Pub/Sub library for implementing broadcasters in jQuery",
"keywords": [
Expand All @@ -24,8 +24,7 @@
],
"ignore": [
".gitignore",
"CHANGELOG.md",
"README.md"
"CHANGELOG.md"
],
"dependencies": {
"jquery": ">=1.8"
Expand Down
2 changes: 1 addition & 1 deletion min/watcher-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions watcher.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Watcher v1.2.1 - 11-23-2015, https://github.com/davegillem/watcher-pubsub
* Watcher v1.2.2 - 12-09-2015, https://github.com/davegillem/watcher-pubsub
* ===================================
* A jQuery plugin for enabling publish/subscribe (Observer) functionality
*
Expand All @@ -20,7 +20,7 @@

var whichWatcher, watcherRef,
isCopy = false,
currEvent = watchers[event];
currEvent = watchers[event] || [];
// check for duplicates
for(var i=0, loopcount=currEvent.length; i<loopcount; i++){
whichWatcher = currEvent[i];
Expand All @@ -42,7 +42,7 @@
_removeWatcher = function(event, id) {
var whichWatcher,
isRemoved = false,
currEvent = watchers[event];
currEvent = watchers[event] || [];
for(var i=0, loopcount=currEvent.length; i<loopcount; i++){
whichWatcher = currEvent[i];
if(whichWatcher.id == id) {
Expand All @@ -58,9 +58,14 @@
_notifyWatchers = function(event, data) {
var whichEvent = watchers[event];
if(whichEvent){
/*
whichEvent && $.each(whichEvent, function() {
this.callback.call($, data);
});
*/
$.each(whichEvent, function() {
this.callback.call($, data);
});
}
},
_getWatchers = function (event){
Expand Down

0 comments on commit 3be4be8

Please sign in to comment.