-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update dependencies #39
Conversation
What's left now are some minor cleanup, docs, changelog, upgrade guide etc. |
And later on refactoring to get rid of |
leveldown.js
Outdated
@@ -83,7 +83,8 @@ SubDown.prototype._open = function (opts, cb) { | |||
return done() | |||
} | |||
|
|||
this.db.on('open', this.open.bind(this, opts, done)) | |||
this.db.once('open', this.open.bind(this, opts, done)) | |||
this.db.open() | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the open, close, open, close test in abstract-leveldown
(which @finnp commented out in previous PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should tweak it to do if (this.db.isClosed()) { this.db.open() }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simplify the whole thing and take advantage of the fact that levelup#open
does process.nextTick(callback)
if already open.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ralphtheninja would this work?
SubDown.prototype._open = function (opts, cb) {
var self = this
this.db.open(function (err) {
if (err) return cb(err)
var subdb = down(self.db, 'subleveldown')
if (subdb && subdb.prefix) {
self.prefix = subdb.prefix + self.prefix
self.leveldown = down(subdb.db)
} else {
self.leveldown = down(self.db)
}
if (self._beforeOpen) self._beforeOpen(cb)
else cb()
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ralphtheninja ping in case you missed this because GH hides it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner! Let me try it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
I'll review tomorrow. |
test/index.js
Outdated
@@ -65,25 +65,26 @@ test('SubDown constructor', function (t) { | |||
test('SubDb main function', function (t) { | |||
t.test('opts.open hook', function (t) { | |||
t.plan(1) | |||
subdb(levelup('loc', {db: memdown}), 'test', { | |||
subdb(levelup(memdown('loc')), 'test', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove the location argument (5x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Could |
@vweevers You mean the default in AbstractLevelDOWN.prototype._serializeKey = function (key) {
return Buffer.isBuffer(key) ? key : String(key)
}
AbstractLevelDOWN.prototype._serializeValue = function (value) {
if (value == null) return ''
return Buffer.isBuffer(value) || process.browser ? value : String(value)
} |
var concat = function (prefix, key, force) {
if (typeof key === 'string' && (force || key.length)) return prefix + key
if (Buffer.isBuffer(key) && (force || key.length)) {
return Buffer.concat([Buffer.from(prefix), key])
}
return key
} So for sub levels to work at all it seems to me that |
@vweevers Also, remember that |
Closes #9
Closes #24
Closes #22
Supersedes #7
Squash when merge.