Skip to content

Commit

Permalink
Merge pull request #134 from megawac/opt-sub
Browse files Browse the repository at this point in the history
Passing callback to subscribe should be optional
  • Loading branch information
jihoonl committed Nov 12, 2014
2 parents 941b74a + 4d64b51 commit fbead6b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/Topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ Topic.prototype.__proto__ = EventEmitter2.prototype;
* * message - the published message
*/
Topic.prototype.subscribe = function(callback) {
this.on('message', callback);
if (typeof callback === 'function') {
this.on('message', callback);
}

if (this.subscribeId) { return; }
this.ros.on(this.name, this._messageCallback);
Expand All @@ -80,6 +82,7 @@ Topic.prototype.subscribe = function(callback) {
*/
Topic.prototype.unsubscribe = function() {
if (!this.subscribeId) { return; }
// Note: Don't call this.removeAllListeners, allow client to handle that themselves
this.ros.off(this.name, this._messageCallback);
this.emit('unsubscribe');
this.ros.callOnConnection({
Expand Down

0 comments on commit fbead6b

Please sign in to comment.