Skip to content

Commit

Permalink
Refactored validationTopics into utils (#447)
Browse files Browse the repository at this point in the history
* Refactored validationTopics & noop into utils

* Leave noop in same files
  • Loading branch information
gnought committed Feb 23, 2020
1 parent c5ee57e commit 323d535
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/client.js
Expand Up @@ -135,7 +135,7 @@ function Client (broker, conn, req) {
}
})
} else if (that.clean === false) {
that.broker.persistence.outgoingClearMessageId(that, _packet, nop)
that.broker.persistence.outgoingClearMessageId(that, _packet, noop)
// we consider this to be an error, since the packet is undefined
// so there's nothing to send
setImmediate(cb)
Expand Down Expand Up @@ -178,7 +178,7 @@ function writeQoS (err, client, packet) {
function onError (err) {
this.errored = true
this.conn.removeAllListeners('error')
this.conn.on('error', nop)
this.conn.on('error', noop)
this.broker.emit(this.id ? 'clientError' : 'connectionError', this, err)
this.close()
}
Expand Down Expand Up @@ -263,7 +263,7 @@ Client.prototype.close = function (done) {
}

this._eos()
this._eos = nop
this._eos = noop

handleUnsubscribe(
this,
Expand All @@ -288,7 +288,7 @@ Client.prototype.close = function (done) {
that.broker.persistence.delWill({
id: that.id,
brokerId: that.broker.id
}, nop)
}, noop)
}
}
})
Expand All @@ -300,7 +300,7 @@ Client.prototype.close = function (done) {
that.connecting = false

conn.removeAllListeners('error')
conn.on('error', nop)
conn.on('error', noop)

if (that.broker.clients[that.id] && that._authorized) {
that.broker.unregisterClient(that)
Expand Down Expand Up @@ -353,4 +353,4 @@ function dequeue () {
}
}

function nop () { }
function noop () {}
2 changes: 1 addition & 1 deletion lib/handlers/subscribe.js
Expand Up @@ -3,7 +3,7 @@
const fastfall = require('fastfall')
const Packet = require('aedes-packet')
const through = require('through2')
const validateTopic = require('./validations')
const { validateTopic } = require('../utils')
const write = require('../write')

const subscribeTopicActions = fastfall([
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/unsubscribe.js
@@ -1,7 +1,7 @@
'use strict'

const write = require('../write')
const validateTopic = require('./validations')
const { validateTopic } = require('../utils')

function UnsubscribeState (client, packet, finish) {
this.client = client
Expand Down
4 changes: 2 additions & 2 deletions lib/qos-packet.js
Expand Up @@ -6,7 +6,7 @@ const util = require('util')
function QoSPacket (original, client) {
Packet.call(this, original, client.broker)

this.writeCallback = nop
this.writeCallback = noop

if (!original.messageId) {
this.messageId = client._nextId
Expand All @@ -22,6 +22,6 @@ function QoSPacket (original, client) {

util.inherits(QoSPacket, Packet)

function nop () {}
function noop () {}

module.exports = QoSPacket
4 changes: 3 additions & 1 deletion lib/handlers/validations.js → lib/utils.js
Expand Up @@ -26,4 +26,6 @@ function validateTopic (topic, message) {
}
}

module.exports = validateTopic
module.exports = {
validateTopic
}

0 comments on commit 323d535

Please sign in to comment.