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

Commit 4fde249

Browse files
committed
refactor: re-introduce else clauses
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.
1 parent fe24e1e commit 4fde249

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ class BlockService {
7272
putMany (blocks) {
7373
if (this.hasExchange()) {
7474
return this._bitswap.putMany(blocks)
75+
} else {
76+
return this._repo.blocks.putMany(blocks)
7577
}
76-
return this._repo.blocks.putMany(blocks)
7778
}
7879

7980
/**
@@ -85,8 +86,9 @@ class BlockService {
8586
get (cid) {
8687
if (this.hasExchange()) {
8788
return this._bitswap.get(cid)
89+
} else {
90+
return this._repo.blocks.get(cid)
8891
}
89-
return this._repo.blocks.get(cid)
9092
}
9193

9294
/**
@@ -102,10 +104,10 @@ class BlockService {
102104

103105
if (this.hasExchange()) {
104106
return this._bitswap.getMany(cids)
107+
} else {
108+
const getRepoBlocks = map((cid) => this._repo.blocks.get(cid))
109+
return getRepoBlocks(cids)
105110
}
106-
107-
const getRepoBlocks = map((cid) => this._repo.blocks.get(cid))
108-
return getRepoBlocks(cids)
109111
}
110112

111113
/**

0 commit comments

Comments
 (0)