Skip to content

Commit

Permalink
Remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
enricostara committed Aug 23, 2015
1 parent deb46b3 commit 880e24c
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/telegram.link.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,7 @@ Client.prototype.stopHttpPollLoop = function () {

// The code:
Client.prototype.registerOnUpdates = function (callback) {
var emitter = this._channel.getParser();
emitter.on('api.type.UpdatesTooLong', callback);
emitter.on('api.type.UpdateShortMessage', callback);
emitter.on('api.type.UpdateShortChatMessage', callback);
emitter.on('api.type.UpdateShort', callback);
emitter.on('api.type.UpdatesCombined', callback);
emitter.on('api.type.Updates', callback);
manageUpdatesListener.call(this, 'on', callback);
};

// ***
Expand All @@ -332,15 +326,19 @@ Client.prototype.registerOnUpdates = function (callback) {

// The code:
Client.prototype.unregisterOnUpdates = function (callback) {
var emitter = this._channel.getParser();
emitter.removeListener('api.type.UpdatesTooLong', callback);
emitter.removeListener('api.type.UpdateShortMessage', callback);
emitter.removeListener('api.type.UpdateShortChatMessage', callback);
emitter.removeListener('api.type.UpdateShort', callback);
emitter.removeListener('api.type.UpdatesCombined', callback);
emitter.removeListener('api.type.Updates', callback);
manageUpdatesListener.call(this, 'removeListener', callback);
};

function manageUpdatesListener (func, callback) {
var emitter = this._channel.getParser();
emitter[func]('api.type.UpdatesTooLong', callback);
emitter[func]('api.type.UpdateShortMessage', callback);
emitter[func]('api.type.UpdateShortChatMessage', callback);
emitter[func]('api.type.UpdateShort', callback);
emitter[func]('api.type.UpdatesCombined', callback);
emitter[func]('api.type.Updates', callback);
}


// ***
// client.**isReady()**
Expand Down

0 comments on commit 880e24c

Please sign in to comment.