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

Commit

Permalink
fix(style): apply CR
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Aug 10, 2016
1 parent 76b6670 commit 9540dfb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
"fs-blob-store": "^5.2.1",
"glob": "^7.0.5",
"hapi": "^14.0.0",
"ipfs-api": "ipfs/js-ipfs-api#8cc853f",
"ipfs-bitswap": "^0.6.0",
"ipfs-api": "ipfs/js-ipfs-api#91de5ac",
"ipfs-block": "^0.3.0",
"ipfs-block-service": "^0.4.0",
"ipfs-merkle-dag": "^0.6.2",
Expand All @@ -81,11 +81,11 @@
"joi": "^9.0.4",
"libp2p-ipfs": "^0.12.1",
"libp2p-ipfs-browser": "^0.12.1",
"lodash.get": "^4.4.0",
"lodash.set": "^4.3.0",
"lodash.get": "^4.4.1",
"lodash.set": "^4.3.1",
"mafmt": "^2.1.1",
"multihashes": "^0.2.2",
"multiaddr": "^2.0.2",
"multihashes": "^0.2.2",
"path-exists": "^3.0.0",
"peer-book": "^0.3.0",
"peer-id": "^0.7.0",
Expand Down
48 changes: 9 additions & 39 deletions src/core/ipfs/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict'

const promisify = require('promisify-es6')
const _get = require('lodash.get')
const _set = require('lodash.set')

module.exports = function config (self) {
return {
Expand All @@ -22,21 +24,11 @@ module.exports = function config (self) {
if (err) {
return callback(err)
}
const keys = key.split('.')
let finished = false
keys.forEach((key) => {
if (finished) {
return
}
if (config[key]) {
config = config[key]
} else {
finished = true
callback(new Error(('Key does not exist in config')))
}
})
if (!finished) {
callback(null, config)
const value = _get(config, key, undefined)
if (!value) {
callback(new Error('Key does not exist in config'))
} else {
callback(null, value)
}
})
}),
Expand All @@ -50,33 +42,11 @@ module.exports = function config (self) {
}

self._repo.config.get((err, config) => {
const configBak = config
if (err) {
return callback(err)
}
const keys = key.split('.')
let finished = false
keys.forEach((key, index) => {
if (finished) {
return
}
if (config[key]) {
if (index === keys.length - 1) {
finished = true
config[key] = value
}
config = config[key]
} else {
if (index === keys.length - 1) {
finished = true
config[key] = value
} else {
config = config[key] = {}
}
}
})

self.config.replace(configBak, callback)
_set(config, key, value)
self.config.replace(config, callback)
})
}),
replace: promisify((config, callback) => {
Expand Down

0 comments on commit 9540dfb

Please sign in to comment.