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

Commit 1f9d550

Browse files
committed
Breaking: hide private properties with Symbol
Effectively removes `SubIterator#iterator`, `SubIterator#prefix` and `SubDown#_beforeOpen`, which likely weren't used externally anyway.
1 parent 58a628a commit 1f9d550

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

leveldown.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const defaultClear = abstract.AbstractLevelDOWN.prototype._clear
1111
const hasOwnProperty = Object.prototype.hasOwnProperty
1212
const nextTick = abstract.AbstractLevelDOWN.prototype._nextTick
1313

14+
const kIterator = Symbol('iterator')
15+
const kPrefix = Symbol('prefix')
16+
const kBeforeOpen = Symbol('beforeOpen')
17+
1418
function concat (prefix, key, force) {
1519
if (typeof key === 'string' && (force || key.length)) return prefix + key
1620
if (Buffer.isBuffer(key) && (force || key.length)) {
@@ -20,8 +24,8 @@ function concat (prefix, key, force) {
2024
}
2125

2226
function SubIterator (db, ite, prefix) {
23-
this.iterator = ite
24-
this.prefix = prefix
27+
this[kIterator] = ite
28+
this[kPrefix] = prefix
2529

2630
abstract.AbstractIterator.call(this, db)
2731
}
@@ -31,20 +35,20 @@ inherits(SubIterator, abstract.AbstractIterator)
3135
SubIterator.prototype._next = function (cb) {
3236
if (maybeError(this.db.leveldown, cb)) return
3337

34-
this.iterator.next((err, key, value) => {
38+
this[kIterator].next((err, key, value) => {
3539
if (err) return cb(err)
36-
if (key) key = key.slice(this.prefix.length)
40+
if (key) key = key.slice(this[kPrefix].length)
3741
cb(err, key, value)
3842
})
3943
}
4044

4145
SubIterator.prototype._seek = function (key) {
42-
this.iterator.seek(concat(this.prefix, key))
46+
this[kIterator].seek(concat(this[kPrefix], key))
4347
}
4448

4549
SubIterator.prototype._end = function (cb) {
4650
if (maybeError(this.db.leveldown, cb)) return
47-
this.iterator.end(cb)
51+
this[kIterator].end(cb)
4852
}
4953

5054
function SubDown (db, prefix, opts) {
@@ -70,7 +74,7 @@ function SubDown (db, prefix, opts) {
7074

7175
this.db = db
7276
this.prefix = separator + prefix + separator
73-
this._beforeOpen = opts.open
77+
this[kBeforeOpen] = opts.open
7478

7579
let manifest = db.supports || {}
7680

@@ -151,7 +155,7 @@ SubDown.prototype._open = function (opts, cb) {
151155
if (this.leveldown.status !== 'open') return cb(new Error('Inner database is not open'))
152156

153157
// TODO: add hooks to abstract-leveldown
154-
if (this._beforeOpen) return this._beforeOpen(cb)
158+
if (this[kBeforeOpen]) return this[kBeforeOpen](cb)
155159

156160
cb()
157161
}

0 commit comments

Comments
 (0)