Skip to content
This repository was archived by the owner on Dec 10, 2020. It is now read-only.

Commit e0d7e25

Browse files
holgerd77ryanio
authored andcommitted
Use nulling coalescing operator for config options assignment, do config member assignment after options clone expression
1 parent a163cae commit e0d7e25

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

lib/config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ export class Config {
7171
// Also a fix for https://github.com/ethereumjs/ethereumjs-vm/issues/757
7272

7373
// TODO: map chainParams (and lib/util.parseParams) to new Common format
74-
this.common = options.common ? options.common : Config.COMMON_DEFAULT
75-
this.logger = options.logger ? options.logger : Config.LOGGER_DEFAULT
76-
this.servers = options.servers ? options.servers : Config.SERVERS_DEFAULT
77-
this.syncmode = options.syncmode ? options.syncmode : Config.SYNCMODE_DEFAULT
78-
this.lightserv = options.lightserv ? options.lightserv : Config.LIGHTSERV_DEFAULT
79-
this.minPeers = options.minPeers ? options.minPeers : Config.MINPEERS_DEFAULT
80-
this.maxPeers = options.maxPeers ? options.maxPeers : Config.MAXPEERS_DEFAULT
74+
this.common = options.common ?? Config.COMMON_DEFAULT
75+
this.logger = options.logger ?? Config.LOGGER_DEFAULT
76+
this.servers = options.servers ?? Config.SERVERS_DEFAULT
77+
this.syncmode = options.syncmode ?? Config.SYNCMODE_DEFAULT
78+
this.lightserv = options.lightserv ?? Config.LIGHTSERV_DEFAULT
79+
this.minPeers = options.minPeers ?? Config.MINPEERS_DEFAULT
80+
this.maxPeers = options.maxPeers ?? Config.MAXPEERS_DEFAULT
8181
}
8282
}

lib/net/peer/peer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ export class Peer extends events.EventEmitter {
4141
constructor(options: any) {
4242
super()
4343

44-
this.config = options.config
45-
4644
options = { ...defaultOptions, ...options }
45+
this.config = options.config
4746

4847
this.id = options.id
4948
this.address = options.address

lib/net/protocol/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export class Protocol extends EventEmitter {
4949
constructor(options?: any) {
5050
super()
5151

52+
options = { ...defaultOptions, ...options }
5253
this.config = options.config
5354

54-
options = { ...defaultOptions, ...options }
5555
this.timeout = options.timeout
5656
this.opened = false
5757
}

lib/net/server/server.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ export class Server extends EventEmitter {
2424
constructor(options: any) {
2525
super()
2626

27-
this.config = options.config
28-
2927
options = { ...defaultOptions, ...options }
28+
this.config = options.config
3029

3130
this.refreshInterval = options.refreshInterval
3231
this.protocols = new Set()

lib/sync/fetcher/fetcher.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ export class Fetcher extends Readable {
4848
constructor(options: any) {
4949
super({ ...options, objectMode: true })
5050

51-
this.config = options.config
52-
5351
options = { ...defaultOptions, ...options }
52+
this.config = options.config
5453

5554
this.pool = options.pool
5655
this.timeout = options.timeout

lib/sync/sync.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ export class Synchronizer extends EventEmitter {
3535
constructor(options?: any) {
3636
super()
3737

38-
this.config = options.config
39-
4038
options = { ...defaultOptions, ...options }
39+
this.config = options.config
4140

4241
this.pool = options.pool
4342
this.chain = options.chain

0 commit comments

Comments
 (0)