[Pkg-javascript-commits] [node-leveldown] 181/492: style tweaks

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:57 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.

commit 2a8f7bf23ffb7278d5fc33eda67faf12d0a6ce75
Author: Rod Vagg <rod at vagg.org>
Date:   Thu Jan 24 10:04:00 2013 +1100

    style tweaks
---
 lib/levelup.js | 81 +++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 55 insertions(+), 26 deletions(-)

diff --git a/lib/levelup.js b/lib/levelup.js
index cd76f0a..5216386 100644
--- a/lib/levelup.js
+++ b/lib/levelup.js
@@ -52,15 +52,14 @@ function LevelUP (location, options) {
   EventEmitter.call(this)
   this.setMaxListeners(Infinity)
   
-  this._options = extend(extend({}, defaultOptions), options)
+  this._options  = extend(extend({}, defaultOptions), options)
   this._location = location
-  this._status = 'new'
+  this._status   = 'new'
 }
 
 inherits(LevelUP, EventEmitter)
 
 LevelUP.prototype.open = function (callback) {
-
   if (this.isOpen()) {
     if (callback)
       process.nextTick(callback.bind(null, null, this))
@@ -71,8 +70,10 @@ LevelUP.prototype.open = function (callback) {
     return callback && this.once('open', callback.bind(null, null, this))
 
   this._status = 'opening'
+
   var execute = function () {
     var db = bridge.createDatabase()
+
     db.open(this._location, this._options, function (err) {
       if (err) {
         err = new errors.OpenError(err)
@@ -80,7 +81,7 @@ LevelUP.prototype.open = function (callback) {
           return callback(err)
         this.emit('error', err)
       } else {
-        this._db = db
+        this._db     = db
         this._status = 'open'
         if (callback)
           callback(null, this)
@@ -96,6 +97,8 @@ LevelUP.prototype.open = function (callback) {
 
 //TODO: we can crash Node by submitting an operation between close() and the actual closing of the database
 LevelUP.prototype.close = function (callback) {
+  var err
+
   if (this.isOpen()) {
     this._status = 'closing'
     this._db.close(function () {
@@ -117,7 +120,7 @@ LevelUP.prototype.close = function (callback) {
       this.close(callback)
     })
   } else {
-    var err = new errors.CloseError('Cannot close unopened database')
+    err = new errors.CloseError('Cannot close unopened database')
     if (callback)
       return callback(err)
     this.emit('error', err)
@@ -137,7 +140,12 @@ LevelUP.prototype.isClosed = function () {
 
 LevelUP.prototype.get = function (key_, options_, callback_) {
   var open = this.isOpen()
-  , callback, options, key, keyEnc, valueEnc, err
+    , callback
+    , options
+    , key
+    , keyEnc
+    , valueEnc
+    , err
   
   if (!open && !this.isClosed()) {
     // limbo, defer the operation
@@ -175,7 +183,11 @@ LevelUP.prototype.get = function (key_, options_, callback_) {
 
 LevelUP.prototype.put = function (key_, value_, options_, callback_) {
   var open = this.isOpen()
-  , callback, options, err, key, value
+    , callback
+    , options
+    , err
+    , key
+    , value
   
   if (!open && !this.isClosed()) {
     // limbo, defer the operation
@@ -187,9 +199,9 @@ LevelUP.prototype.put = function (key_, value_, options_, callback_) {
   callback = getCallback(options_, callback_)
   
   if (open) {
-    options  = getOptions(options_, this._options)
-    key      = toSlice[options.keyEncoding   || options.encoding](key_)
-    value    = toSlice[options.valueEncoding || options.encoding](value_)
+    options = getOptions(options_, this._options)
+    key     = toSlice[options.keyEncoding   || options.encoding](key_)
+    value   = toSlice[options.valueEncoding || options.encoding](value_)
 
     this._db.put(key, value, options, function (err) {
       if (err) {
@@ -212,9 +224,13 @@ LevelUP.prototype.put = function (key_, value_, options_, callback_) {
 }
 
 LevelUP.prototype.del = function (key_, options_, callback_) {
-  var open, callback, options, err, key
+  var open = this.isOpen()
+    , callback
+    , options
+    , err
+    , key
   
-  if (!(open = this.isOpen()) && !this.isClosed()) {
+  if (!open && !this.isClosed()) {
     // limbo, defer the operation
     return this.once('ready', function () {
       this.del(key_, options_, callback_)
@@ -224,8 +240,9 @@ LevelUP.prototype.del = function (key_, options_, callback_) {
   callback = getCallback(options_, callback_)
   
   if (open) {
-    options  = getOptions(options_, this._options)
-    key      = toSlice[options.keyEncoding   || options.encoding](key_)
+    options = getOptions(options_, this._options)
+    key     = toSlice[options.keyEncoding || options.encoding](key_)
+
     this._db.del(key, options, function (err) {
       if (err) {
         err = new errors.WriteError(err)
@@ -247,7 +264,12 @@ LevelUP.prototype.del = function (key_, options_, callback_) {
 }
 
 LevelUP.prototype.batch = function (arr_, options_, callback_) {
-  var callback, options, keyEncoding, valueEncoding, err, arr
+  var callback
+    , options
+    , keyEncoding
+    , valueEncoding
+    , err
+    , arr
   
   if (!this.isOpen() && !this.isClosed()) {
     return this.once('ready', function () {
@@ -276,12 +298,11 @@ LevelUP.prototype.batch = function (arr_, options_, callback_) {
 
     arr = arr_.map(function (e) {
       if (e.type !== undefined && e.key !== undefined) {
-        var o = {
-          type  : e.type
-          , key   : toSlice[keyEncoding](e.key)
-        }
+        var o = { type: e.type, key: toSlice[keyEncoding](e.key) }
+
         if (e.value !== undefined)
           o.value = toSlice[valueEncoding](e.value)
+
         return o
       }
       return {}
@@ -332,7 +353,11 @@ LevelUP.prototype.approximateSize = function(start, end, callback) {
 }
 
 LevelUP.prototype.readStream = function (options) {
-  options = extend(extend({}, this._options), typeof options == 'object' ? options : {})
+  options = extend(
+      extend({}, this._options)
+    , typeof options == 'object' ? options : {}
+  )
+
   return readStream.create(
       options
     , this
@@ -344,15 +369,19 @@ LevelUP.prototype.readStream = function (options) {
 
 LevelUP.prototype.keyStream = function (options) {
   return this.readStream(
-      extend(options ? extend({}, options) : {}
-    , { keys: true, values: false })
+      extend(
+          options ? extend({}, options) : {}
+        , { keys: true, values: false }
+      )
   )
 }
 
 LevelUP.prototype.valueStream = function (options) {
   return this.readStream(
-      extend(options ? extend({}, options) : {}
-    , { keys: false, values: true })
+      extend(
+          options ? extend({}, options) : {}
+        , { keys: false, values: true }
+      )
   )
 }
 
@@ -374,12 +403,12 @@ module.exports = function (location, options, callback) {
 
   if (typeof options == 'function') {
     callback = options
-    options = {}
+    options  = {}
   }
 
   if (typeof location != 'string') {
     message = 'Must provide a location for the database'
-    error = new errors.InitializationError(message)
+    error   = new errors.InitializationError(message)
 
     if (callback) {
       return callback(error)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list