Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Use arrow functions where this is needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 8, 2021
1 parent 345c17e commit 8240c24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
20 changes: 9 additions & 11 deletions abstract-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@ function AbstractIterator (db) {
}

AbstractIterator.prototype.next = function (callback) {
const self = this

if (typeof callback !== 'function') {
throw new Error('next() requires a callback argument')
}

if (self._ended) {
if (this._ended) {
nextTick(callback, new Error('cannot call next() after end()'))
return self
return this
}

if (self._nexting) {
if (this._nexting) {
nextTick(callback, new Error('cannot call next() before previous next() has completed'))
return self
return this
}

self._nexting = true
self._next(function () {
self._nexting = false
callback.apply(null, arguments)
this._nexting = true
this._next((err, ...rest) => {
this._nexting = false
callback(err, ...rest)
})

return self
return this
}

AbstractIterator.prototype._next = function (callback) {
Expand Down
14 changes: 6 additions & 8 deletions abstract-leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function AbstractLevelDOWN (manifest) {
}

AbstractLevelDOWN.prototype.open = function (options, callback) {
const self = this
const oldStatus = this.status

if (typeof options === 'function') callback = options
Expand All @@ -33,12 +32,12 @@ AbstractLevelDOWN.prototype.open = function (options, callback) {
options.errorIfExists = !!options.errorIfExists

this.status = 'opening'
this._open(options, function (err) {
this._open(options, (err) => {
if (err) {
self.status = oldStatus
this.status = oldStatus
return callback(err)
}
self.status = 'open'
this.status = 'open'
callback()
})
}
Expand All @@ -48,20 +47,19 @@ AbstractLevelDOWN.prototype._open = function (options, callback) {
}

AbstractLevelDOWN.prototype.close = function (callback) {
const self = this
const oldStatus = this.status

if (typeof callback !== 'function') {
throw new Error('close() requires a callback argument')
}

this.status = 'closing'
this._close(function (err) {
this._close((err) => {
if (err) {
self.status = oldStatus
this.status = oldStatus
return callback(err)
}
self.status = 'closed'
this.status = 'closed'
callback()
})
}
Expand Down

0 comments on commit 8240c24

Please sign in to comment.