Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

optimized mulit event callbacks

  • Loading branch information...
commit 9fdf364c18edf29ca53412a80bafcfa465822775 1 parent 01a1800
Adriano Raiano authored

Showing 2 changed files with 7 additions and 2 deletions. Show diff stats Hide diff stats

  1. +1 1  example/exampleInstance.js
  2. +6 1 lib/observer.js
2  example/exampleInstance.js
@@ -14,7 +14,7 @@ hub.on('commands', function(data) {
14 14 hub.emit('event:event2', {event: 'event2', id: data.id});
15 15 }
16 16
17   - hub.emit('events', data);
  17 + hub.emit('event:bla', data);
18 18 });
19 19
20 20 // and the command
7 lib/observer.js
@@ -38,7 +38,12 @@ Observer.prototype = {
38 38 getPendingCommand: function(commandId, eventName) {
39 39 eventName = eventName || '';
40 40 var callback = this.commands[commandId + eventName];
41   - delete this.commands[commandId + eventName];
  41 + if (!callback) {
  42 + callback = this.commands[commandId];
  43 + delete this.commands[commandId];
  44 + } else {
  45 + delete this.commands[commandId + eventName];
  46 + }
42 47 return callback;
43 48 }
44 49

0 comments on commit 9fdf364

Please sign in to comment.
Something went wrong with that request. Please try again.