Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
refactor: re-introduce else clauses
Browse files Browse the repository at this point in the history
I make the distinction between early returns and "either-or" cases when
it is about if-else clauses.

Here we have an "either-or" case. Either there is an exchange, then do
one thing, or if there is no exchange, do the other thing.
  • Loading branch information
vmx committed Jun 17, 2019
1 parent fe24e1e commit 4803679
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class BlockService {
put (block) {
if (this.hasExchange()) {
return this._bitswap.put(block)
} else {
return this._repo.blocks.put(block)
}
return this._repo.blocks.put(block)
}

/**
Expand All @@ -72,8 +73,9 @@ class BlockService {
putMany (blocks) {
if (this.hasExchange()) {
return this._bitswap.putMany(blocks)
} else {
return this._repo.blocks.putMany(blocks)
}
return this._repo.blocks.putMany(blocks)
}

/**
Expand All @@ -85,8 +87,9 @@ class BlockService {
get (cid) {
if (this.hasExchange()) {
return this._bitswap.get(cid)
} else {
return this._repo.blocks.get(cid)
}
return this._repo.blocks.get(cid)
}

/**
Expand All @@ -102,10 +105,10 @@ class BlockService {

if (this.hasExchange()) {
return this._bitswap.getMany(cids)
} else {
const getRepoBlocks = map((cid) => this._repo.blocks.get(cid))
return getRepoBlocks(cids)
}

const getRepoBlocks = map((cid) => this._repo.blocks.get(cid))
return getRepoBlocks(cids)
}

/**
Expand Down

0 comments on commit 4803679

Please sign in to comment.