Skip to content

Commit 2319634

Browse files
committed
Breaking: modernize syntax (Level/community#98)
1 parent 92271b2 commit 2319634

File tree

4 files changed

+86
-91
lines changed

4 files changed

+86
-91
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ updates:
77
ignore:
88
- dependency-name: dependency-check
99
- dependency-name: nyc
10-
- dependency-name: standard
1110
- dependency-name: tempy

level-ws.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
var Writable = require('readable-stream').Writable
2-
var inherits = require('inherits')
3-
var extend = require('xtend')
1+
'use strict'
42

5-
var defaultOptions = { type: 'put' }
3+
const Writable = require('readable-stream').Writable
4+
const inherits = require('inherits')
5+
const extend = require('xtend')
6+
7+
const defaultOptions = { type: 'put' }
68

79
function WriteStream (db, options) {
810
if (!(this instanceof WriteStream)) {
@@ -22,64 +24,56 @@ function WriteStream (db, options) {
2224
this._flushing = false
2325
this._maxBufferLength = options.maxBufferLength || Infinity
2426

25-
var self = this
26-
27-
this.on('finish', function () {
28-
self.emit('close')
27+
this.on('finish', () => {
28+
this.emit('close')
2929
})
3030
}
3131

3232
inherits(WriteStream, Writable)
3333

3434
WriteStream.prototype._write = function (data, enc, next) {
35-
var self = this
36-
if (self.destroyed) return
35+
if (this.destroyed) return
3736

38-
if (!self._flushing) {
39-
self._flushing = true
40-
process.nextTick(function () { self._flush() })
37+
if (!this._flushing) {
38+
this._flushing = true
39+
process.nextTick(() => { this._flush() })
4140
}
4241

43-
if (self._buffer.length >= self._maxBufferLength) {
44-
self.once('_flush', function (err) {
45-
if (err) return self.destroy(err)
46-
self._write(data, enc, next)
42+
if (this._buffer.length >= this._maxBufferLength) {
43+
this.once('_flush', (err) => {
44+
if (err) return this.destroy(err)
45+
this._write(data, enc, next)
4746
})
4847
} else {
49-
self._buffer.push(extend({ type: self._options.type }, data))
48+
this._buffer.push(extend({ type: this._options.type }, data))
5049
next()
5150
}
5251
}
5352

5453
WriteStream.prototype._flush = function () {
55-
var self = this
56-
var buffer = self._buffer
54+
const buffer = this._buffer
5755

58-
if (self.destroyed) return
56+
if (this.destroyed) return
5957

60-
self._buffer = []
61-
self._db.batch(buffer, cb)
62-
63-
function cb (err) {
64-
self._flushing = false
58+
this._buffer = []
59+
this._db.batch(buffer, (err) => {
60+
this._flushing = false
6561

66-
if (!self.emit('_flush', err) && err) {
62+
if (!this.emit('_flush', err) && err) {
6763
// There was no _flush listener.
68-
self.destroy(err)
64+
this.destroy(err)
6965
}
70-
}
66+
})
7167
}
7268

7369
WriteStream.prototype._final = function (cb) {
74-
var self = this
75-
7670
if (this._flushing) {
7771
// Wait for scheduled or in-progress _flush()
78-
this.once('_flush', function (err) {
72+
this.once('_flush', (err) => {
7973
if (err) return cb(err)
8074

8175
// There could be additional buffered writes
82-
self._final(cb)
76+
this._final(cb)
8377
})
8478
} else if (this._buffer && this._buffer.length) {
8579
this.once('_flush', cb)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"level-concat-iterator": "^2.0.0",
2525
"nyc": "^14.0.0",
2626
"secret-event-listener": "^1.0.0",
27-
"standard": "^14.1.0",
27+
"standard": "^16.0.3",
2828
"tape": "^5.0.1",
2929
"tempy": "^0.2.1"
3030
},

0 commit comments

Comments
 (0)