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

Commit 4803679

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 4803679

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class BlockService {
5959
put (block) {
6060
if (this.hasExchange()) {
6161
return this._bitswap.put(block)
62+
} else {
63+
return this._repo.blocks.put(block)
6264
}
63-
return this._repo.blocks.put(block)
6465
}
6566

6667
/**
@@ -72,8 +73,9 @@ class BlockService {
7273
putMany (blocks) {
7374
if (this.hasExchange()) {
7475
return this._bitswap.putMany(blocks)
76+
} else {
77+
return this._repo.blocks.putMany(blocks)
7578
}
76-
return this._repo.blocks.putMany(blocks)
7779
}
7880

7981
/**
@@ -85,8 +87,9 @@ class BlockService {
8587
get (cid) {
8688
if (this.hasExchange()) {
8789
return this._bitswap.get(cid)
90+
} else {
91+
return this._repo.blocks.get(cid)
8892
}
89-
return this._repo.blocks.get(cid)
9093
}
9194

9295
/**
@@ -102,10 +105,10 @@ class BlockService {
102105

103106
if (this.hasExchange()) {
104107
return this._bitswap.getMany(cids)
108+
} else {
109+
const getRepoBlocks = map((cid) => this._repo.blocks.get(cid))
110+
return getRepoBlocks(cids)
105111
}
106-
107-
const getRepoBlocks = map((cid) => this._repo.blocks.get(cid))
108-
return getRepoBlocks(cids)
109112
}
110113

111114
/**

0 commit comments

Comments
 (0)