From 1fac4fb11caca70eae46697aca54934efa6c5729 Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Tue, 29 Aug 2017 13:28:12 +0200 Subject: [PATCH] :sparkles: callback is always a function --- lib/batch.js | 2 +- lib/levelup.js | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/batch.js b/lib/batch.js index 7501eced..12972241 100644 --- a/lib/batch.js +++ b/lib/batch.js @@ -66,7 +66,7 @@ Batch.prototype.write = function (callback) { this.batch.write(function (err) { if (err) { return dispatchError(levelup, new WriteError(err), callback) } levelup.emit('batch', ops) - if (callback) { callback() } + callback() }) } catch (err) { throw new WriteError(err) diff --git a/lib/levelup.js b/lib/levelup.js index 6fe2599a..a4bade24 100644 --- a/lib/levelup.js +++ b/lib/levelup.js @@ -73,12 +73,12 @@ LevelUP.prototype.open = function (callback) { if (!callback) [ callback, promise ] = promisify() if (this.isOpen()) { - if (callback) { process.nextTick(function () { callback(null, self) }) } + process.nextTick(callback, null, self) return promise } if (this._isOpening()) { - if (callback) this.once('open', function () { callback(null, self) }) + this.once('open', function () { callback(null, self) }) return promise } @@ -89,7 +89,7 @@ LevelUP.prototype.open = function (callback) { return dispatchError(self, new OpenError(err), callback) } self.db = self._db - if (callback) { callback(null, self) } + callback(null, self) self.emit('open') self.emit('ready') }) @@ -106,13 +106,13 @@ LevelUP.prototype.close = function (callback) { if (this.isOpen()) { this.db.close(function () { self.emit('closed') - if (callback) { callback.apply(null, arguments) } + callback.apply(null, arguments) }) this.emit('closing') this.db = new DeferredLevelDOWN(this._db) - } else if (this.isClosed() && callback) { + } else if (this.isClosed()) { process.nextTick(callback) - } else if (this.db.status === 'closing' && callback) { + } else if (this.db.status === 'closing') { this.once('closed', callback) } else if (this._isOpening()) { this.once('open', function () { @@ -160,7 +160,7 @@ LevelUP.prototype.get = function (key, options, callback) { } return dispatchError(self, err, callback) } - if (callback) { callback(null, value) } + callback(null, value) }) return promise @@ -187,7 +187,7 @@ LevelUP.prototype.put = function (key, value, options, callback) { return dispatchError(self, new WriteError(err), callback) } self.emit('put', key, value) - if (callback) { callback() } + callback() }) return promise @@ -214,7 +214,7 @@ LevelUP.prototype.del = function (key, options, callback) { return dispatchError(self, new WriteError(err), callback) } self.emit('del', key) - if (callback) { callback() } + callback() }) return promise @@ -250,7 +250,7 @@ LevelUP.prototype.batch = function (arr, options, callback) { return dispatchError(self, new WriteError(err), callback) } self.emit('batch', arr) - if (callback) { callback() } + callback() }) return promise