Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit cc843cf

Browse files
committed
refactor(read-preference): simplify arguments management
1 parent c5b4752 commit cc843cf

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/topologies/read_preference.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,15 @@
4141
* @return {ReadPreference}
4242
*/
4343
const ReadPreference = function(mode, tags, options) {
44+
if (tags && !Array.isArray(tags) && typeof tags === 'object')
45+
(options = tags), (tags = undefined);
46+
4447
this.mode = mode;
4548
this.tags = tags;
46-
this.options = options;
49+
this.options = options || {};
4750

48-
// Add the maxStalenessSeconds value to the read Preference
49-
if (this.options && this.options.maxStalenessSeconds != null) {
50-
this.options = options;
51-
this.maxStalenessSeconds =
52-
this.options.maxStalenessSeconds >= 0 ? this.options.maxStalenessSeconds : null;
53-
} else if (tags && typeof tags === 'object') {
54-
(this.options = tags), (tags = null);
51+
if (this.options.maxStalenessSeconds != null && this.options.maxStalenessSeconds > 0) {
52+
this.maxStalenessSeconds = this.options.maxStalenessSeconds;
5553
}
5654
};
5755

0 commit comments

Comments
 (0)